Greasy Fork 还支持 简体中文。

NEET Lib

NEET Bot Library

目前為 2019-09-05 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/383201/730801/NEET%20Lib.js

  1. // ==UserScript==
  2. // @name NEET Lib
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3.0
  5. // @description NEET Bot Library
  6. // @author eterNEETy
  7. // @match http://game.granbluefantasy.jp/
  8. // @grant none
  9. // @namespace https://greasyfork.org/users/292830
  10. // ==/UserScript==
  11. // jshint esversion: 6
  12. // jshint -W138
  13.  
  14. /*
  15.  
  16. changelog:
  17.  
  18. 1.1.0:
  19. - added init()
  20. - changed `let main_path` to `path.main`
  21.  
  22. 1.2.0:
  23. - changed charMoveSet cid
  24.  
  25. 1.3.0:
  26. - added discord_mention
  27. */
  28.  
  29.  
  30. // environment info
  31. const xhr = new XMLHttpRequest(),
  32. server = "http://localhost:2487",
  33. margin = {"top":91,"left":0},
  34. game_url = "http://game.granbluefantasy.jp/";
  35.  
  36. let debug = true,
  37. reload_counter;
  38.  
  39. let zoom = 1;
  40.  
  41. let my_profile = "Main: ";
  42. let is_host = "false";
  43. let battle;
  44. let is_wiped = true;
  45. let discord_mention = '';
  46.  
  47. let quests_id = [], monsters = [], monsters_name = [];
  48. const recovery_items = ['Elixir','Half Elixir','Soul Balm','Soul Berry'];
  49. let reloadable_skill = ["Four-Sky's Sorrow", "Thunder Raid"];
  50. let tracker_reward_weapons = [];
  51. let tracker_reward_summons = [];
  52. let tracker_reward_items = [recovery_items[0], recovery_items[1], recovery_items[2], recovery_items[3],'Gold Brick','Damascus Grain','Silver Centrum'];
  53.  
  54.  
  55. const kaguya = {"name":"Kaguya", "star":0},
  56. white_rabbit = {"name":"White Rabbit", "star":3},
  57. black_rabbit = {"name":"Black Rabbit", "star":3},
  58. huanglong = {"name":"Huanglong", "star":3},
  59. shiva = {"name":"Shiva", "star":3},
  60. shiva0 = {"name":"Shiva", "star":0},
  61. varuna = {"name":"Varuna", "star":3},
  62. bonito = {"name":"Bonito", "star":4},
  63. yggdrasil = {"name":"Yggdrasil Omega", "star":4},
  64. uriel = {"name":"Uriel", "star":0},
  65. tiamat = {"name":"Tiamat Omega", "star":4},
  66. bahamut = {"name":"Bahamut", "star":5},
  67. lucifer = {"name":"Lucifer", "star":5};
  68. const leech_summons = [kaguya,white_rabbit,black_rabbit];
  69.  
  70. // const game variable
  71. const trials_id = ["990011","990021","990031","990041","990051","990061","990071"],
  72. trial_id = "990011",
  73. select_summon_path = "supporter/";
  74.  
  75.  
  76. // path
  77. let path = {
  78. 'main': '',
  79. "item":"#item",
  80. "quest":"#quest",
  81. "support":"#quest/supporter/",
  82. "assist":"#quest/assist",
  83. "unclaimed":"#quest/assist/unclaimed",
  84. "trial":"#quest/supporter/"+trial_id+"/17",
  85. };
  86.  
  87. // element dom query selector
  88. let skill_char = "#prt-command-top > div > div > div.lis-character";
  89. let skill_abi = ".btn-command-character > div.prt-ability-state > div.lis-ability-state.ability";
  90. let query = {
  91. "battle_ui": {
  92. "skill": {
  93. "char1": {
  94. "skill1": skill_char + "0" + skill_abi + "1",
  95. "skill2": skill_char + "0" + skill_abi + "2",
  96. "skill3": skill_char + "0" + skill_abi + "3",
  97. "skill4": skill_char + "0" + skill_abi + "4",
  98. },
  99. "char2": {
  100. "skill1": skill_char + "1" + skill_abi + "1",
  101. "skill2": skill_char + "1" + skill_abi + "2",
  102. "skill3": skill_char + "1" + skill_abi + "3",
  103. "skill4": skill_char + "1" + skill_abi + "4",
  104. },
  105. "char3": {
  106. "skill1": skill_char + "2" + skill_abi + "1",
  107. "skill2": skill_char + "2" + skill_abi + "2",
  108. "skill3": skill_char + "2" + skill_abi + "3",
  109. "skill4": skill_char + "2" + skill_abi + "4",
  110. },
  111. "char4": {
  112. "skill1": skill_char + "3" + skill_abi + "1",
  113. "skill2": skill_char + "3" + skill_abi + "2",
  114. "skill3": skill_char + "3" + skill_abi + "3",
  115. "skill4": skill_char + "3" + skill_abi + "4",
  116. },
  117. },
  118. "skill_pop_up": {
  119. "char1": "div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character0.btn-command-character > img",
  120. "char2": "div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character1.btn-command-character > img",
  121. "char3": "div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character2.btn-command-character > img",
  122. "char4": "div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character3.btn-command-character > img",
  123. "char5": "div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character4.btn-command-character > img",
  124. "char6": "div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character5.btn-command-character > img",
  125. },
  126. "ougi": ".btn-lock",
  127. "toggle_ougi": {
  128. true: ".lock0",
  129. false: ".lock1",
  130. },
  131. "char_ico": ".prt-party>.prt-member>.btn-command-character>img.img-chara-command",
  132. "summon_panel": ".prt-summon-list>.prt-list-top.btn-command-summon",
  133. "chat":".btn-chat.comment.display-on",
  134. "chat_pop_up": {
  135. "dialog":".txt-chat-pop",
  136. },
  137. "heal":"#prt-sub-command-group>.btn-temporary",
  138. "heal_pop_up": {
  139. "green": ".lis-item.item-small",
  140. "blue": ".lis-item.item-large",
  141. "use": ".pop-usual.pop-raid-item.pop-show>.prt-popup-footer>.btn-usual-use",
  142. "cancel": ".pop-usual.pop-raid-item.pop-show>.prt-popup-footer>.btn-usual-cancel",
  143. },
  144. "trial_pop_up": {
  145. "close": ".pop-usual.pop-trialbattle-notice.pop-show>.prt-popup-footer>.btn-usual-close",
  146. },
  147. "backup_pop_up": {
  148. "request": ".pop-usual.pop-start-assist.pop-show>.prt-popup-footer>.btn-usual-text",
  149. "cancel": ".pop-usual.pop-start-assist.pop-show>.prt-popup-footer>.btn-usual-cancel",
  150. },
  151. "button": {
  152. "assist": ".prt-multi-buttons>.btn-assist",
  153. },
  154. },
  155. "assist_ui": {
  156. "tab_id": "#tab-id",
  157. "tab_multi": "#tab-multi",
  158. "tab_event": "#tab-event",
  159. "unclaimed": ".btn-unclaimed",
  160. },
  161. "poker": {
  162. "canvas": "#canv",
  163. "deal": ".prt-start",
  164. "ok": ".prt-ok",
  165. "yes": ".prt-yes",
  166. "no": ".prt-no",
  167. "low": ".prt-double-select>.prt-low-shine",
  168. "high": ".prt-double-select>.prt-high-shine",
  169. },
  170. "ok":".btn-usual-ok",
  171. };
  172.  
  173. // general item variable
  174. let tracked_item = false;
  175.  
  176. function getMessage(pilot) {
  177. const message = {
  178. "raid" : {
  179. "panel" : {
  180. "open" : pilot+"Opening quest/raid panel",
  181. "pick" : pilot+"Picking quest/raid difficulties",
  182. },
  183. "select_party" : pilot+"Selecting party",
  184. "finish" : pilot+"Raid finished",
  185. "trial" : {
  186. "close_pop_up" : pilot+"In trial, closing pop up",
  187. "open_menu" : pilot+ "In trial, click menu",
  188. "retreat" : pilot+ "In trial, click retreat",
  189. "ok" : pilot+ "In trial, click ok",
  190. "end" : pilot+"Retreated from trial, back to main raid",
  191. }
  192. },
  193. "summon" : {
  194. "select" : pilot+"Selecting summon",
  195. "pick_tab" : pilot+"Clicking summon element tab",
  196. "not_found" : pilot+"Support summon not found, going to trial",
  197. },
  198. "replenish" : {
  199. "elixir" : {
  200. "half_elixir" : {
  201. "use" : pilot+"Not enough AP, using half elixir",
  202. "used" : pilot+"Half elixir used",
  203. }
  204. },
  205. "soul" : {
  206. "soul_berry" : {
  207. "use" : pilot+"Not enough EP, using soul berry",
  208. "used" : pilot+"soul berry used",
  209. }
  210. }
  211. },
  212. "ok" : pilot+"Clicking ok",
  213. };
  214. return message;
  215. }
  216.  
  217. function reloadNow() {
  218. console.log(reloadNow.name);
  219. xhr.open('POST', server);
  220. xhr.send(JSON.stringify([{"cmd":"press","key":"f5"}]));
  221. window.location.reload();
  222. }
  223.  
  224. function reload(mod_value=1) {
  225. clearInterval(reload_counter);
  226. let current_path = window.location.hash;
  227. let count = 1;
  228. reload_counter = setInterval(function() {
  229. if(window.location.hash != current_path){
  230. clearInterval(reload_counter);
  231. }
  232. console.log("reloading in "+(mod_value-count).toString());
  233. if (count%mod_value===0){
  234. clearInterval(reload_counter);
  235. reloadNow();
  236. }
  237. count += 1;
  238. }, 1000);
  239. }
  240.  
  241. function setDebug() {
  242. if(!debug){
  243. console.log("DEBUG is turned OFF");
  244. if(!window.console) window.console = {};
  245. let methods = ["log", "debug", "warn", "info"];
  246. for(let i=0;i<methods.length;i++){
  247. console[methods[i]] = function(){};
  248. }
  249. }
  250. }
  251.  
  252. function readBody(xhr) {
  253. let data;
  254. if (!xhr.responseType || xhr.responseType === "text") {
  255. data = xhr.responseText;
  256. } else if (xhr.responseType === "document") {
  257. data = xhr.responseXML;
  258. } else {
  259. data = xhr.response;
  260. }
  261. return data;
  262. }
  263.  
  264. function gotoHash(key){
  265. let hash_path;
  266. if (path[key] !== undefined) {
  267. hash_path = path[key];
  268. }else{
  269. if (key.indexOf("#")!==0) {
  270. hash_path = "#"+key;
  271. }
  272. }
  273. window.location.href = game_url + hash_path;
  274. }
  275.  
  276. function scrollTo(query,qid=0) {
  277. document.querySelectorAll(query)[qid].scrollIntoViewIfNeeded();
  278. }
  279.  
  280. function checkExist(query,qid=0) {
  281. let el_exist = false;
  282. if (document.querySelectorAll(query).length > qid){
  283. if (document.querySelectorAll(query)[qid].getBoundingClientRect().width > 0 && document.querySelectorAll(query)[qid].getBoundingClientRect().height > 0) {
  284. el_exist = true;
  285. }
  286. }
  287. return el_exist;
  288. }
  289.  
  290. function checkEl(query,qid=0,callback=false) {
  291. let old_top = -1;
  292. let old_left = -1;
  293. let loop_checkEl = setInterval(function() {
  294. console.log(checkEl.name + " " + query + "[" + qid + "]");
  295. if (checkExist(query,qid)) {
  296. if (old_top==document.querySelectorAll(query)[qid].getBoundingClientRect().top && old_left==document.querySelectorAll(query)[qid].getBoundingClientRect().left) {
  297. clearInterval(loop_checkEl);
  298. if (typeof callback == "function") {
  299. callback();
  300. }
  301. }else{
  302. old_top = document.querySelectorAll(query)[qid].getBoundingClientRect().top;
  303. old_left = document.querySelectorAll(query)[qid].getBoundingClientRect().left;
  304. }
  305. }
  306. }, 200);
  307. }
  308.  
  309. function checkEls(queries,callback=false) {
  310. let exist_result;
  311. let loop_checkEls = setInterval(function() {
  312. exist_result = [];
  313. for (let i in queries) {
  314. console.log(checkEls.name + " " + queries[i].query + "[" + queries[i].qid + "]");
  315. exist_result.push(checkExist(queries[i].query,queries[i].qid));
  316. }
  317. if (exist_result.indexOf(false)===-1) {
  318. clearInterval(loop_checkEls);
  319. if (typeof callback == "function") {
  320. callback();
  321. }
  322. }
  323. }, 300);
  324. }
  325.  
  326. function checkElsOR(queries,callback=false) {
  327. let exist_result;
  328. let loop_checkEls = setInterval(function() {
  329. exist_result = [];
  330. for (let i in queries) {
  331. console.log(checkElsOR.name + " " + queries[i].query + "[" + queries[i].qid + "]");
  332. exist_result.push(checkExist(queries[i].query,queries[i].qid));
  333. }
  334. if (exist_result.indexOf(true)>=0) {
  335. clearInterval(loop_checkEls);
  336. if (typeof callback == "function") {
  337. callback();
  338. }
  339. }
  340. }, 300);
  341. }
  342.  
  343. function checkError() {
  344. let q_cnt_error = ".cnt-error";
  345. let q_pop_up = ".pop-usual.common-pop-error.pop-show";
  346. let q_abi_pop_up = ".pop-usual.pop-raid-ability-error.pop-show";
  347. let check_error = setInterval(function() {
  348. console.log(checkError.name);
  349. if (checkExist(q_pop_up,0) || checkExist(q_cnt_error,0) || checkExist(q_abi_pop_up,0)) {
  350. let cmd = [];
  351. console.log("error_found");
  352. let do_reload = false;
  353. let level = "notif";
  354. let msg = "Uncatagorized error found";
  355. // let msg = "Connection error, refreshing disabled"
  356. if (checkExist(q_abi_pop_up,0)) {
  357. do_reload = true;
  358. msg = my_profile + document.querySelector(q_abi_pop_up+">.prt-popup-body>.txt-popup-body").innerHTML;
  359. level = "process";
  360. } else {
  361. if (checkExist(q_pop_up+">.prt-popup-header",0)) {
  362. if (document.querySelector(q_pop_up+">.prt-popup-header").innerHTML=="Access Verification") {
  363. clearInterval(reload_counter);
  364. clearInterval(check_error);
  365. msg = my_profile+"Captcha detected " + discord_mention;
  366. console.log("Captcha detected");
  367. }else if (document.querySelector(q_pop_up+">.prt-popup-header").innerHTML=="エラー") {
  368. if (checkExist(q_pop_up+">.prt-popup-body>.txt-popup-body>div",0)) {
  369. if (typeof document.querySelector(q_pop_up+">.prt-popup-body>.txt-popup-body>div").innerHTML == "string") {
  370. if (document.querySelector(q_pop_up+">.prt-popup-body>.txt-popup-body>div").innerHTML.indexOf("Network Error")>=0) {
  371. clearInterval(reload_counter);
  372. console.log("Error connection");
  373. do_reload = true;
  374. msg = my_profile+"Error connection, reloading";
  375. level = "process";
  376. }
  377. }
  378. }
  379. }
  380. }
  381. if (checkExist(q_pop_up+">.prt-popup-body>.txt-popup-body",0)) {
  382. if (document.querySelector(q_pop_up+">.prt-popup-body>.txt-popup-body").innerHTML=="Check your pending battles.") {
  383. console.log("check raid");
  384. level = "process";
  385. msg = my_profile+"Check your pending battle";
  386. clickEl(".prt-popup-footer>.btn-usual-ok",0,my_profile+"Clicking ok pop up pending battles");
  387. }
  388. }
  389. }
  390. if (do_reload){
  391. cmd.push({"cmd":"press","key":"f5"});
  392. }
  393. cmd.push({"cmd":"log","level":level,"msg":msg});
  394. xhr.open('POST', server);
  395. xhr.send(JSON.stringify(cmd));
  396. if (do_reload){
  397. window.location.reload();
  398. }
  399. }
  400. }, 5000);
  401. }
  402.  
  403. function getCoord(el){
  404. zoom = parseInt(document.getElementById("mobage-game-container").style.zoom);
  405. let x, y, output;
  406. el = el.getBoundingClientRect();
  407. if (el.width>0 && el.height>0) {
  408. x = (el.width / 2) + el.left;
  409. y = (el.height / 2) + el.top;
  410. if(el.width>40){
  411. x += Math.floor(Math.random() * 41)-20;
  412. }else if(el.width>20){
  413. x += Math.floor(Math.random() * 21)-10;
  414. }else if(el.width>10){
  415. x += Math.floor(Math.random() * 11)-5;
  416. }
  417. if(el.height>10){
  418. y += Math.floor(Math.random() * 11)-5;
  419. }
  420. output = [(x*zoom)+margin.left,(y*zoom)+margin.top];
  421. }else{
  422. output = 0;
  423. }
  424. return output;
  425. }
  426.  
  427. function getMarginCoord(query,qid){
  428. let el = document.querySelectorAll(query)[qid].getBoundingClientRect();
  429. return {"top":el.top+margin.top,"left":el.left+margin.left};
  430. }
  431.  
  432. function clickNow(query,qid=0,msg=my_profile+"clickNow called",callback=false){
  433. let el = document.querySelectorAll(query)[qid];
  434. let output = false;
  435. if (checkExist(query,qid)) {
  436. output = true;
  437. let cmd = [];
  438. cmd.push({"cmd":"clickIt","param":getCoord(el)});
  439. cmd.push({"cmd":"log","level":"process","msg":msg});
  440. xhr.open("POST", server);
  441. xhr.send(JSON.stringify(cmd));
  442. if (typeof callback == "function") {
  443. callback();
  444. }
  445. }
  446. return output;
  447. }
  448.  
  449. function clickEl(query,qid=0,msg=my_profile+"clickEl called",callback=false){
  450. let init_clickEl = function() {
  451. clickNow(query,qid,msg,callback);
  452. };
  453. checkEl(query,qid,init_clickEl);
  454. }
  455.  
  456. function clickObject(obj){
  457. if (obj == "ok"){
  458. clickEl(".btn-usual-ok",0,message.ok);
  459. }
  460. }
  461.  
  462. function clickAndNegCheck(query,qid=0,msg="clickAndNegCheck called",callback=false,ticks=5){
  463. let old_href = window.location.href;
  464. let old_top = -1;
  465. let old_left = -1;
  466. let match = ticks-1;
  467. let str_clickAndNegCheck = clickAndNegCheck.name + ", el: " + query + "["+(qid.toString())+"] \n- match = ";
  468. let init_clickAndNegCheck = function() {
  469. let loop_clickAndNegCheck = setInterval(function() {
  470. console.log(str_clickAndNegCheck+(match.toString()));
  471. if (!(checkExist(query,qid))) {
  472. clearInterval(loop_clickAndNegCheck);
  473. if (typeof callback == "function") {
  474. callback();
  475. }
  476. }else if (old_href != window.location.href) {
  477. clearInterval(loop_clickAndNegCheck);
  478. }else{
  479. if (checkExist(query,qid)) {
  480. if (old_top==document.querySelectorAll(query)[qid].getBoundingClientRect().top && old_left==document.querySelectorAll(query)[qid].getBoundingClientRect().left) {
  481. if (match % ticks == 0) {
  482. clickNow(query,qid,msg);
  483. }
  484. match += 1;
  485. }else{
  486. old_top = document.querySelectorAll(query)[qid].getBoundingClientRect().top;
  487. old_left = document.querySelectorAll(query)[qid].getBoundingClientRect().left;
  488. }
  489. }
  490. }
  491. }, 100);
  492. };
  493. checkEl(query,qid,init_clickAndNegCheck);
  494. }
  495.  
  496. function clickAndCheck(query1,qid1=0,query2,qid2=0,msg="clickAndCheck called",callback=false,ticks=5){
  497. let old_href = window.location.href;
  498. let old_top = -1;
  499. let old_left = -1;
  500. let match = ticks-1;
  501. let str_clickAndCheck = clickAndCheck.name + ", check: " + query2 + "["+(qid2.toString())+"], click: " + query1 + "["+(qid1.toString())+"] \n- match = ";
  502. let loop_clickAndCheck = setInterval(function() {
  503. console.log(str_clickAndCheck+(match.toString()));
  504. if (checkExist(query2,qid2)) {
  505. clearInterval(loop_clickAndCheck);
  506. if (typeof callback == "function") {
  507. callback();
  508. }
  509. }else if (old_href != window.location.href) {
  510. clearInterval(loop_clickAndCheck);
  511. }else{
  512. if (checkExist(query1,qid1)) {
  513. if (old_top==document.querySelectorAll(query1)[qid1].getBoundingClientRect().top && old_left==document.querySelectorAll(query1)[qid1].getBoundingClientRect().left) {
  514. if (match % ticks == 0) {
  515. clickNow(query1,qid1,msg);
  516. }
  517. match += 1;
  518. }else{
  519. old_top = document.querySelectorAll(query1)[qid1].getBoundingClientRect().top;
  520. old_left = document.querySelectorAll(query1)[qid1].getBoundingClientRect().left;
  521. }
  522. }
  523. }
  524. }, 100);
  525. }
  526.  
  527. function popUpNotEnough(rep) {
  528. const query = ".btn-use-full.index-1",
  529. qid = 0,
  530. msg = message.replenish.elixir.half_elixir.use;
  531. let cmd = [], coordinate, consumable_data;
  532. consumable_data = my_profile+"Consumable Status:";
  533. for (let i = 0; i < rep.length; i++) {
  534. consumable_data += ("\n- "+rep[i].name+": "+rep[i].number);
  535. }
  536. let init_popUpNotEnough = function() {
  537. coordinate = getCoord(document.querySelectorAll(query)[qid]);
  538. if (coordinate!==0){
  539. cmd.push({"cmd":"clickIt","param":coordinate});
  540. cmd.push({"cmd":"log","level":"process","msg":msg});
  541. cmd.push({"cmd":"log","level":"summary","msg":consumable_data,"split":0});
  542. xhr.open('POST', server);
  543. xhr.send(JSON.stringify(cmd));
  544. }
  545. };
  546. checkEl(query,qid,init_popUpNotEnough);
  547.  
  548. }
  549.  
  550. function clickAndCheckSkill(query,qid=0,msg="clickAndCheckSkill called",callback=false,special_case=false){
  551. console.log(clickAndCheckSkill.name);
  552. console.log(callback);
  553. console.log(query);
  554. console.log(qid);
  555. let old_class = document.querySelectorAll(query)[qid].parentNode.classList[0];
  556. console.log(old_class);
  557. let loop_clickAndCheckSkill = setInterval(function() {
  558. console.log(checkEl.name + " " + query + "[" + qid + "]");
  559. if (Array.from(document.querySelectorAll(query)[qid].parentNode.parentNode.classList).indexOf("tmp-mask")>=0 || Array.from(document.querySelectorAll(query)[qid].parentNode.parentNode.classList).indexOf("btn-ability-unavailable")>=0){
  560. clearInterval(loop_clickAndCheckSkill);
  561. console.log(clickAndCheckSkill.name + " case normal");
  562. if (typeof callback == "function") {
  563. callback();
  564. }
  565. // Bea skill
  566. }else if(special_case===1 && document.querySelectorAll(query)[qid].parentNode.classList[0] != old_class){
  567. clearInterval(loop_clickAndCheckSkill);
  568. console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  569. if (typeof callback == "function") {
  570. callback();
  571. }
  572. // Out of sight & sage of eternity
  573. }else if(special_case===2){
  574. let do_click = true;
  575. console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  576. let popup_query = "#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header";
  577. if (checkExist(popup_query,0)) {
  578. if (document.querySelector("#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header").innerHTML == "Use Skill"){
  579. clearInterval(loop_clickAndCheckSkill);
  580. do_click = false;
  581. if (typeof callback == "function") {
  582. callback();
  583. }
  584. }
  585. }
  586. if (do_click) {
  587. if (checkExist(query,qid)) {
  588. clickNow(query,qid,msg);
  589. }
  590. }
  591. }else{
  592. if (checkExist(query,qid)) {
  593. clickNow(query,qid,msg);
  594. }
  595. }
  596.  
  597. }, 500);
  598. }
  599.  
  600. function getCharStr(char_id){
  601. let char;
  602. if (char_id==1){
  603. char = "MC";
  604. }else{
  605. char = "NPC"+((char_id-1).toString());
  606. }
  607. return char;
  608. }
  609.  
  610. function useSkill(char_id,abi_id,callback=false,special_case=false){
  611. console.log(useSkill.name + ", char: "+char_id+", ability: " + (abi_id.toString()) + ", case: "+special_case);
  612. let char = getCharStr(char_id);
  613. abi_id = parseInt(abi_id)-1;
  614. console.log(".prt-command-chara.chara"+(char_id.toString())+">div>div.lis-ability");
  615. if (Array.from(document.querySelectorAll(".prt-command-chara.chara"+(char_id.toString())+">div>div.lis-ability")[abi_id].classList).indexOf("btn-ability-available")>=0 && document.querySelectorAll(".prt-command-chara.chara"+(char_id.toString())+">div>div.lis-ability")[abi_id].getBoundingClientRect().width>0){
  616. clickAndCheckSkill(".prt-command-chara.chara"+(char_id.toString())+">div>div>div>.img-ability-icon",abi_id,my_profile+"Clicking "+char+" skill"+((abi_id+1).toString()),callback,special_case);
  617. }else{
  618. if (typeof callback == "function") {
  619. callback();
  620. }
  621. }
  622. }
  623.  
  624. function useSkills(char_id, skill_list, callback=false, special_case=[false]) {
  625. console.log(useSkills.name);
  626. if (skill_list.length>0) {
  627. console.log(useSkills.name + ", char: "+char_id+", ability: " + (skill_list[0].toString()) + ", case: "+special_case[0]);
  628. let new_skill_list = Object.values(skill_list);
  629. new_skill_list.splice(0,1);
  630. console.log("dari useSkills");
  631. console.log(new_skill_list);
  632. console.log("---");
  633. let abi_id = parseInt(skill_list[0])-1;
  634. let char = battle.player.param[char_id-1].name;
  635. let next_skill = function(){console.log("dari next_skill");useSkills(char_id, new_skill_list, callback, special_case);};
  636. console.log(next_skill);
  637. console.log(abi_id);
  638. if (Array.from(document.querySelectorAll(".prt-command-chara.chara"+(char_id.toString())+">div>div.lis-ability")[abi_id].classList).indexOf("btn-ability-available")>=0 && document.querySelectorAll(".prt-command-chara.chara"+(char_id.toString())+">div>div.lis-ability")[abi_id].getBoundingClientRect().width>0){
  639. console.log(".prt-command-chara.chara"+(char_id.toString())+">div>div>div>.img-ability-icon");
  640. console.log(abi_id);
  641. console.log(my_profile+"Clicking "+char+" skill"+((abi_id+1).toString()));
  642. console.log(next_skill);
  643. console.log(special_case[0]);
  644. clickAndCheckSkill(".prt-command-chara.chara"+(char_id.toString())+">div>div>div>.img-ability-icon",abi_id,my_profile+"Clicking "+char+" skill"+((abi_id+1).toString()),next_skill,special_case[0]);
  645. }else{
  646. if (typeof callback == "function") {
  647. next_skill();
  648. }
  649. }
  650. } else {
  651. if (typeof callback == "function") {
  652. callback();
  653. }
  654. }
  655.  
  656. }
  657.  
  658. function clickBackup(callback=false) {
  659. let check_backup = function() {
  660. let el_btn, backup_msg;
  661. if (Array.from(document.querySelector(query.battle_ui.backup_pop_up.request).classList).indexOf("disable") >= 0) {
  662. el_btn = query.battle_ui.backup_pop_up.cancel;
  663. backup_msg = "cancel";
  664. } else {
  665. el_btn = query.battle_ui.backup_pop_up.request;
  666. backup_msg = "request";
  667. }
  668. clickAndNegCheck(el_btn,0,my_profile+"Clicking "+backup_msg,callback,10);
  669. };
  670. clickAndCheck(query.battle_ui.button.assist,0,query.battle_ui.backup_pop_up.request,0,my_profile+"Clicking backup",check_backup,10);
  671. }
  672.  
  673. function clickBack(callback=false){
  674. clickAndCheck(".btn-command-back.display-on",0,"div.prt-member",0,my_profile+"Clicking back",callback,10);
  675. }
  676.  
  677. function clickSummonPanel(callback=false){
  678. console.log(clickSummonPanel.name);
  679. let query1 = ".prt-list-top.btn-command-summon.summon-on";
  680. let query2 = ".prt-summon-list.opened";
  681. let query3 = ".prt-list-top.btn-command-summon.summon-off";
  682. let qid1 = 0, qid2 = 0, qid3 = 0;
  683. let msg = my_profile+"Clicking summon panel";
  684. let old_top = -1;
  685. let old_left = -1;
  686. let loop_clickAndCheck = setInterval(function() {
  687. console.log(clickAndCheck.name + ", check: " + query2 + "["+(qid2.toString())+"], click: " + query1 + "["+(qid1.toString())+"]");
  688. if (checkExist(query2,qid2) || checkExist(query3,qid3)) {
  689. clearInterval(loop_clickAndCheck);
  690. if (typeof callback == "function") {
  691. callback();
  692. }
  693. }else{
  694. if (checkExist(query1,qid1)) {
  695. if (old_top==document.querySelectorAll(query1)[qid1].getBoundingClientRect().top && old_left==document.querySelectorAll(query1)[qid1].getBoundingClientRect().left) {
  696. clickNow(query1,qid1,msg);
  697. }else{
  698. old_top = document.querySelectorAll(query1)[qid1].getBoundingClientRect().top;
  699. old_left = document.querySelectorAll(query1)[qid1].getBoundingClientRect().left;
  700. }
  701. }
  702. }
  703. }, 200);
  704. }
  705.  
  706. function clickSummon(summon_id,callback1=false,callback2=false){
  707. console.log(clickSummon.name);
  708. summon_id = summon_id-1;
  709. if (Array.from(document.querySelectorAll(".lis-summon")[summon_id].classList).indexOf("btn-summon-available")>=0){
  710. let loop_clickSummon = setInterval(function() {
  711. if (document.querySelectorAll(".lis-summon>img")[summon_id].getBoundingClientRect().x === document.querySelectorAll(".lis-summon>img")[0].getBoundingClientRect().x + (summon_id * (document.querySelectorAll(".lis-summon>img")[0].getBoundingClientRect().width+2))){
  712. clearInterval(loop_clickSummon);
  713. clickAndCheck(".lis-summon>img",summon_id,".pop-usual.pop-summon-detail>div>.btn-usual-ok.btn-summon-use",0,my_profile+"Clicking summon "+((summon_id+1).toString()),callback1);
  714. }
  715. }, 300);
  716. }else{
  717. if (typeof callback2 == "function") {
  718. callback2();
  719. }
  720. }
  721. }
  722.  
  723. function clickOkSummon(callback=false){
  724. console.log(clickOkSummon.name);
  725. let el_ok = ".pop-usual.pop-summon-detail>div>.btn-usual-ok.btn-summon-use";
  726. if (document.querySelector(el_ok) !== null){
  727. clickAndCheck(el_ok,0,"div.prt-member",0,my_profile+"Clicking summon ok",callback);
  728. }else{
  729. if (typeof callback == "function") {
  730. callback();
  731. }
  732. }
  733. }
  734. function clickOkSummon2(summon_id,callback=false){
  735. let el_ok = ".pop-usual.pop-summon-detail>div>.btn-usual-ok.btn-summon-use";
  736. let summon_el = '.lis-summon[pos="'+(summon_id.toString())+'"]';
  737. if (document.querySelector(el_ok) !== null){
  738. let loop_clickOkSummon2 = setInterval(function() {
  739. console.log(clickOkSummon2.name + ", click: " + el_ok + "[0]");
  740. if (Array.from(document.querySelector(summon_el).classList).indexOf("tmp-mask")>=0 || Array.from(document.querySelector(summon_el).classList).indexOf("btn-summon-unavailable")>=0) {
  741. clearInterval(loop_clickOkSummon2);
  742. if (typeof callback == "function") {
  743. callback();
  744. }
  745. }else{
  746. if (checkExist(el_ok,0)) {
  747. clickNow(el_ok,0,my_profile+"Clicking summon ok2");
  748. }
  749. }
  750. }, 1000);
  751. }else{
  752. if (typeof callback == "function") {
  753. callback();
  754. }
  755. }
  756. }
  757.  
  758. function selectSummon(preferred_summon,is_trial=false){
  759. reload(20);
  760.  
  761. let init_selectSummon = function() {
  762. console.log(init_selectSummon.name);
  763. reload(10);
  764. const attrib_list = [6,0,1,2,3,4,5];
  765. let query_summon_list = ".btn-supporter.lis-supporter";
  766. let el_summon_list = document.querySelectorAll(query_summon_list);
  767. let preferred_summon_id = false;
  768. let picked_attrib_id = false;
  769. let picked_summon_id = false;
  770. let picked_is_friend = false;
  771. let is_friend;
  772. let picked_summon_stars = false;
  773. let picked_summon_level = false;
  774. let picked_summon_plus = false;
  775. let msg;
  776. let cmd = [], summon_list = {};
  777. if (el_summon_list.length>50 && document.querySelector(".prt-supporter-battle-announce")===null && document.querySelector(".txt-confirm-comment")===null && document.querySelector(".prt-check-auth")===null && document.querySelector(".btn-check-auth")===null){
  778. msg = my_profile+"Verify not appear, summon list length is "+(el_summon_list.length.toString());
  779. console.log(msg);
  780.  
  781. // check if raid is trial
  782. if (!is_trial){
  783. console.log("not trial");
  784. for (let i = 0; i < el_summon_list.length; i++) {
  785. let match_preferred = false, replace = false;
  786. let temp_var, summon_detail, summon_name, summon_level, summon_stars, summon_plus;
  787. temp_var = el_summon_list[i].querySelector(".prt-supporter-summon");
  788. summon_detail = temp_var.innerHTML.trim();
  789. temp_var = el_summon_list[i].querySelector(".prt-supporter-summon");
  790. summon_detail = temp_var.innerHTML.trim();
  791. summon_name = summon_detail.substring(summon_detail.indexOf("</span>")+8,summon_detail.length);
  792. summon_level = parseInt(temp_var.children[0].innerHTML.replace("Lvl ",""));
  793. temp_var = Array.from(el_summon_list[i].querySelector(".prt-summon-skill").classList);
  794. if (temp_var.indexOf("bless-rank3-style")>=0){
  795. summon_stars = 5;
  796. }else if (temp_var.indexOf("bless-rank2-style")>=0){
  797. summon_stars = 4;
  798. }else if (temp_var.indexOf("bless-rank1-style")>=0){
  799. summon_stars = 3;
  800. }else{
  801. summon_stars = 0;
  802. }
  803. temp_var = el_summon_list[i].querySelector(".prt-summon-quality");
  804. if (temp_var !== null){
  805. summon_plus = parseInt(temp_var.innerHTML.replace("+",""));
  806. }else{
  807. summon_plus = 0;
  808. }
  809. temp_var = false;
  810. is_friend = Array.from(el_summon_list[i].querySelector(".prt-supporter-name").classList).indexOf("ico-friend")>=0;
  811.  
  812. // loop preferred summon list (specified in parameter)
  813. for (let j = 0; j < preferred_summon.length; j++) {
  814. if (preferred_summon[j].name==summon_name && preferred_summon[j].star<=summon_stars){
  815. match_preferred = true;
  816. temp_var = j;
  817. }
  818. }
  819.  
  820.  
  821. if (match_preferred){
  822. if (picked_attrib_id===false && picked_summon_id===false){
  823. replace = true;
  824. }else{
  825. if (preferred_summon_id>temp_var){
  826. replace = true;
  827. }else if(preferred_summon_id==temp_var){
  828. if (summon_stars>picked_summon_stars){
  829. replace = true;
  830. }else if(summon_stars==picked_summon_stars){
  831. if (!picked_is_friend && is_friend){
  832. replace = true;
  833. }else if(picked_is_friend && is_friend){
  834. if (summon_level>picked_summon_level){
  835. replace = true;
  836. }else if(summon_level==picked_summon_level){
  837. if (summon_plus>picked_summon_plus){
  838. replace = true;
  839. }
  840. }
  841. }
  842. }
  843. }
  844. }
  845. }
  846. if (replace){
  847. picked_attrib_id = Array.from(document.querySelectorAll(".prt-supporter-attribute")).indexOf(el_summon_list[i].parentElement);
  848. picked_summon_id = i;
  849. preferred_summon_id = temp_var;
  850. picked_summon_stars = summon_stars;
  851. picked_is_friend = is_friend;
  852. picked_summon_level = summon_level;
  853. picked_summon_plus = summon_plus;
  854. }
  855. }
  856. console.log([picked_attrib_id,picked_summon_id,preferred_summon_id]);
  857. if (picked_summon_id===false){
  858. console.log("go to trial");
  859. cmd.push({"cmd":"log","level":"process","msg":message.summon.not_found});
  860. xhr.open("POST", server);
  861. xhr.send(JSON.stringify(cmd));
  862. gotoHash("trial");
  863. }else{
  864. console.log("summon_found");
  865. let pickSummon = function() {
  866. scrollTo(query_summon_list,picked_summon_id);
  867. clickEl(query_summon_list,picked_summon_id,message.summon.select);
  868. };
  869. let clickAndCheckSummon = function(callback=false){
  870. let el_tab_ele_ico = ".prt-type-text";
  871. let el_summon_container = ".prt-supporter-attribute";
  872. let loop_clickAndCheckSummon = setInterval(function() {
  873. console.log(clickAndCheckSummon.name + ", check: " + el_summon_container + "[" + picked_attrib_id + "], click: " + el_tab_ele_ico + "["+(attrib_list[picked_attrib_id].toString())+"]");
  874. if (Array.from(document.querySelectorAll(el_summon_container)[picked_attrib_id].classList).indexOf("disableView") == -1) {
  875. clearInterval(loop_clickAndCheckSummon);
  876. if (typeof callback == "function") {
  877. callback();
  878. }
  879. }else{
  880. if (checkExist(el_tab_ele_ico, attrib_list[picked_attrib_id])) {
  881. clickNow(el_tab_ele_ico, attrib_list[picked_attrib_id], message.summon.pick_tab);
  882. }
  883. }
  884. }, 300);
  885. };
  886. clickAndCheckSummon(pickSummon);
  887. }
  888. }else{
  889. console.log("is trial");
  890. query_summon_list = ".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter";
  891. el_summon_list = document.querySelectorAll(query_summon_list);
  892. for (let i = 0; i < el_summon_list.length; i++) {
  893. is_friend = Array.from(el_summon_list[i].querySelector(".prt-supporter-name").classList).indexOf("ico-friend")>=0;
  894. if (!is_friend){
  895. if (picked_summon_id===false){
  896. picked_summon_id = i;
  897. }
  898. }
  899. }
  900. if (picked_summon_id!==false){
  901. scrollTo(".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter",picked_summon_id);
  902. clickEl(".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter",picked_summon_id,message.summon.select);
  903. }
  904. }
  905. }else{
  906. msg = my_profile+"Verify might appear, summon list length is "+(el_summon_list.length.toString());
  907. clearInterval(reload_counter);
  908. console.log(msg);
  909. cmd.push({"cmd":"log","level":"process","msg":msg});
  910. cmd.push({"cmd":"log","level":"notif","msg":msg});
  911. xhr.open("POST", server);
  912. xhr.send(JSON.stringify(cmd));
  913. }
  914. };
  915. checkEl(".prt-supporter-title",0,init_selectSummon);
  916. }
  917.  
  918. function doChat(callback=false) {
  919. console.log(doChat.name);
  920. let clickDialog = function() {
  921. console.log(clickDialog.name);
  922. clickAndNegCheck(query.battle_ui.chat_pop_up.dialog,0,my_profile+"Clicking chat dialog",callback);
  923. };
  924. let clickChat = function() {
  925. console.log(clickChat.name);
  926. if (checkExist(query.battle_ui.chat+">.ico-attention",0)) {
  927. clickAndCheck(query.battle_ui.chat,0,query.battle_ui.chat_pop_up.dialog,0,my_profile+"Clicking chat pop up",clickDialog,20);
  928. }else{
  929. if (typeof callback == "function") {
  930. callback();
  931. }
  932. }
  933. };
  934. checkEl(query.battle_ui.chat,0,clickChat);
  935. }
  936.  
  937. function backFromTrial(){
  938. let cmd = [];
  939. cmd.push({"cmd":"log","level":"process","msg":message.raid.trial.end});
  940. xhr.open("POST", server);
  941. xhr.send(JSON.stringify(cmd));
  942. gotoHash("main");
  943. }
  944.  
  945. function gotoResult() {
  946. console.log(gotoResult.name);
  947. console.log(is_host);
  948. if (is_host || window.location.hash.indexOf("#raid/")>=0) {
  949. gotoHash("quest");
  950. }else if (window.location.hash.indexOf("#raid_multi")>=0) {
  951. reloadNow();
  952. }
  953. }
  954.  
  955. function attack(rep){
  956. console.log(attack.name);
  957. let cmd = [];
  958. let reps = rep.scenario;
  959. let win = false;
  960. let is_last_raid = false;
  961. let ougi = 0;
  962. let msg = "";
  963. for (let i = 0; i < reps.length; i++) {
  964. if (reps[i].cmd =="win"){
  965. if (reps[i].is_last_raid){is_last_raid=true;}
  966. win=true;
  967. }else if (reps[i].cmd=="special" || reps[i].cmd=="special_npc"){
  968. const char_name = battle.player.param[parseInt(battle.formation[reps[i].pos])].name;
  969. msg += my_profile+char_name+" used ougi \""+reps[i].name+"\".\n";
  970. if (reps[i].total){msg += my_profile+char_name+" dealt "+reps[i].total[0].split.join("")+" damage.\n";}
  971. ougi++;
  972. }else if (reps[i].cmd=="attack" && reps[i].from=="player"){
  973. const char_name = battle.player.param[parseInt(battle.formation[reps[i].pos])].name;
  974. if (reps[i].damage.length==3){
  975. msg += my_profile+char_name+" made a triple attack.\n";
  976. }else if (reps[i].damage.length==2){
  977. msg += my_profile+char_name+" made a double attack.\n";
  978. }
  979. msg += my_profile+char_name+ " dealt ";
  980. for (let ii=0; ii<reps[i].damage.length; ii++){
  981. msg += reps[i].damage[ii][0].value.toString();
  982. if (ii<reps[i].damage.length-1){
  983. msg += ", ";
  984. }else{
  985. msg += " damage.\n";
  986. }
  987. }
  988. }
  989. }
  990.  
  991. if(win){
  992. cmd.push({"cmd":"log","level":"process","msg":msg+my_profile+"Foe defeated."});
  993. }else{
  994. cmd.push({"cmd":"log","level":"process","msg":msg+my_profile+"Foe is still alive."});
  995. cmd.push({"cmd":"press","key":"f5"});
  996. }
  997. xhr.open('POST', server);
  998. xhr.send(JSON.stringify(cmd));
  999. if(win && is_last_raid){
  1000. gotoResult();
  1001. }else if(win){
  1002. clickEl(".btn-result",0,my_profile+"Go to next round");
  1003. }
  1004. }
  1005.  
  1006. function skillUsed(rep){
  1007. console.log(skillUsed.name);
  1008. let do_reload = false;
  1009. let reps = rep.scenario;
  1010. let win = false, is_last_raid = false;
  1011. console.log(reps);
  1012. for (let i = 0; i < reps.length; i++) {
  1013. const scenario = reps[i];
  1014. if (scenario.cmd =="ability"){
  1015. if (reloadable_skill.indexOf(scenario.name)>= 0) {
  1016. do_reload = true;
  1017. }
  1018. }else if (scenario.cmd =="damage") {
  1019. if (scenario.to == "player") {
  1020. for (let j = 0; j < scenario.list.length; j++) {
  1021. const s = scenario.list[j];
  1022. if (s.hp !== undefined && s.pos !== undefined) {
  1023. battle.player.param[s.pos].hp = s.hp;
  1024. }
  1025. }
  1026. }
  1027. }else if (scenario.cmd =="finished"){
  1028. win=true;
  1029. is_last_raid=true;
  1030. }else if (scenario.cmd == "win"){
  1031. if (scenario.is_last_raid) {
  1032. is_last_raid=true;
  1033. }
  1034. win=true;
  1035. }
  1036. }
  1037. if(win && is_last_raid){
  1038. gotoResult();
  1039. }else if(do_reload){
  1040. reloadNow();
  1041. }
  1042. }
  1043.  
  1044. function summonUsed(rep){
  1045. console.log(summonUsed.name);
  1046. let do_reload = false;
  1047. let reps = rep.scenario;
  1048. let win = false,
  1049. is_last_raid = false;
  1050. for (let i = 0; i < reps.length; i++) {
  1051. const scenario = reps[i];
  1052. if (scenario.cmd == "finished"){
  1053. win=true;
  1054. is_last_raid=true;
  1055. }else if (scenario.cmd == "win"){
  1056. if (scenario.is_last_raid){
  1057. is_last_raid=true;
  1058. }
  1059. win=true;
  1060. }
  1061. }
  1062. if (battle.lyria_pos >= 0) {
  1063. do_reload = true;
  1064. }
  1065. if(win && is_last_raid){
  1066. gotoResult();
  1067. }else if(do_reload){
  1068. reloadNow();
  1069. }
  1070. }
  1071.  
  1072. function potUsed(rep) {
  1073. console.log(potUsed.name);
  1074. let reps = rep.scenario;
  1075. for (let i = 0; i < reps.length; i++) {
  1076. const scenario = reps[i];
  1077. if (scenario.cmd == "heal") {
  1078. for (let j = 0; j < scenario.list.length; j++) {
  1079. const s = scenario.list[j];
  1080. if (s.hp !== undefined && s.pos !== undefined) {
  1081. battle.player.param[s.pos].hp = s.hp;
  1082. }
  1083. }
  1084. }
  1085. }
  1086. }
  1087.  
  1088. function clickAttack(callback=false) {
  1089. let hp = ((parseInt(battle.boss.param[0].hp) / parseInt(battle.boss.param[0].hpmax)) * 100).toString();
  1090. if (hp.indexOf(".")>=0){
  1091. hp = hp.substring(0,hp.indexOf("."));
  1092. }
  1093. console.log(hp);
  1094. let attack_msg = my_profile+"Foe hp is "+hp+"% left, commencing attack";
  1095. clickAndCheck(".btn-attack-start.display-on",0,".btn-attack-cancel.btn-cancel.display-on",0,attack_msg,callback,20);
  1096. }
  1097.  
  1098. function charMoveSet(cid,skill_list,callback) {
  1099. if (!(Number.isInteger(cid))) {
  1100. cid = battle.player.param.findIndex(x => x.name === cid);
  1101. }
  1102. console.log(charMoveSet.name + ': ' + cid);
  1103. let char = battle.player.param[cid];
  1104. console.log(char.name);
  1105. if (char !== undefined) {
  1106. let can_use_skill = true;
  1107. if (skill_list.length>0) {
  1108. let new_skill_list = Object.values(skill_list);
  1109. for (let i = 0; i < skill_list.length; i++) {
  1110. const skill = skill_list[i];
  1111. if (document.querySelector(query.battle_ui.skill['char'+(cid+1).toString()]['skill'+(skill.toString())]).attributes.state.value != "2") {
  1112. new_skill_list.splice(new_skill_list.indexOf(skill),1);
  1113. }
  1114. }
  1115. skill_list = new_skill_list;
  1116. if ("debuff" in char.condition) {
  1117. for (let i = 0; i < char.condition.debuff.length; i++) {
  1118. const debuff = char.condition.debuff[i];
  1119. if (debuff.status == "1111") {
  1120. can_use_skill = false;
  1121. }
  1122. }
  1123. }
  1124. }
  1125. if (char.alive===1 && skill_list.length>0 && can_use_skill) {
  1126. let click_back = function(){clickBack(callback);};
  1127. let use_skills = function(){useSkills(cid+1,skill_list,click_back);};
  1128. let click_char = function(){clickChar(cid+1,use_skills);};
  1129. click_char();
  1130. } else {
  1131. if (typeof callback == "function") {
  1132. callback();
  1133. }
  1134. }
  1135. } else {
  1136. if (typeof callback == "function") {
  1137. callback();
  1138. }
  1139. }
  1140. }
  1141.  
  1142.  
  1143. function toggleOugi(ougi, callback=false) {
  1144. let init_toggleOugi = function() {
  1145. let current_ougi = "."+document.querySelector(query.battle_ui.ougi).classList[1];
  1146. if (query.battle_ui.toggle_ougi[ougi] != current_ougi){
  1147. clickAndCheck(query.battle_ui.ougi + current_ougi, 0, query.battle_ui.ougi + query.battle_ui.toggle_ougi[ougi], 0, my_profile+"Set toggle ougi to "+(ougi.toString()), callback);
  1148. }else{
  1149. if (typeof callback == "function") {
  1150. callback();
  1151. }
  1152. }
  1153. };
  1154. checkEl(query.battle_ui.ougi,0,init_toggleOugi);
  1155. }
  1156.  
  1157. function summoning(summon_id,callback=false) {
  1158. console.log(summoning.name);
  1159. let summon_cd;
  1160. console.log('test 1');
  1161. if (summon_id === 5) {
  1162. console.log('test 2');
  1163. summon_cd = battle.supporter.recast;
  1164. console.log('test 3');
  1165. } else if (battle.summon[summon_id] !== undefined) {
  1166. console.log('test 4');
  1167. summon_cd = battle.summon[summon_id].recast;
  1168. console.log('test 5');
  1169. }
  1170. console.log('test 6');
  1171. if (summon_cd === "0") {
  1172. console.log('test 7');
  1173. let summon_ok = function(){clickOkSummon(callback);};
  1174. let summon = function(){clickSummon(summon_id+1,summon_ok,callback);};
  1175. let summon_p = function(){clickSummonPanel(summon);};
  1176. summon_p();
  1177. } else {
  1178. console.log('test 8');
  1179. if (typeof callback == "function") {
  1180. callback();
  1181. }
  1182. }
  1183. }
  1184.  
  1185. function startRaid(rep){
  1186. reload(15);
  1187. battle = rep;
  1188. is_host = rep.is_host;
  1189. for (let i = 0; i < battle.player.param.length; i++) {
  1190. const c = battle.player.param[i];
  1191. if (c.alive === 1) {
  1192. is_wiped = false;
  1193. }
  1194. }
  1195. let usePot = function(pot_type,char_id=false,callback=false) {
  1196. console.log(usePot.name);
  1197. let is_front_healable = [];
  1198. let is_player_reviveable = [];
  1199. let is_player_healable = [];
  1200. for (const i in battle.player.param) {
  1201. if (battle.player.param.hasOwnProperty(i)) {
  1202. if (battle.player.param[i].alive === 1) {
  1203. is_player_reviveable.push(false);
  1204. is_player_healable.push(battle.player.param[i].hpmax - battle.player.param[i].hp !== 0);
  1205. }else{
  1206. is_player_reviveable.push(true);
  1207. is_player_healable.push(false);
  1208. }
  1209. }
  1210. }
  1211. for (const i in rep.formation) {
  1212. if (rep.formation.hasOwnProperty(i)) {
  1213. const alive_id = parseInt(rep.formation[i]);
  1214. is_front_healable.push(battle.player.param[alive_id].hpmax - battle.player.param[alive_id].hp !== 0);
  1215. }
  1216. }
  1217. let query_qty = ">.txt-having>.having-num";
  1218. let clickUse = function() {
  1219. clickAndNegCheck(query.battle_ui.heal_pop_up.use,0,my_profile+"Clicking use from pot pop up",callback);
  1220. };
  1221. let clickFront = function() {
  1222. clickAndCheck(query.battle_ui.char_ico,char_id,query.battle_ui.summon_panel+":not(.mask-black)",0,my_profile+"Clicking char_ico from pot pop up",callback);
  1223. };
  1224. let clickCancel = function() {
  1225. clickAndNegCheck(query.battle_ui.heal_pop_up.cancel,0,my_profile+"Clicking cancel from pot pop up",callback);
  1226. };
  1227. let clickPot = function() {
  1228. console.log(clickPot.name);
  1229. if (checkExist(query.battle_ui.heal_pop_up[pot_type]+query_qty)) {
  1230. if ( parseInt(document.querySelector(query.battle_ui.heal_pop_up[pot_type]+query_qty).innerHTML) > 0 ) {
  1231. if (pot_type == "blue") {
  1232. clickAndNegCheck(query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking "+ pot_type +" pot",clickUse);
  1233. }else if (pot_type == "green") {
  1234. clickAndNegCheck(query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking "+ pot_type +" pot",clickFront);
  1235. }else{
  1236. console.log("pot_type unknown");
  1237. clickCancel();
  1238. }
  1239. }else{
  1240. console.log("pot qty not > 0");
  1241. clickCancel();
  1242. }
  1243. }else{
  1244. console.log("element not exist");
  1245. clickCancel();
  1246. }
  1247. };
  1248. let clickHeal = function() {
  1249. console.log(clickHeal.name);
  1250. clickAndCheck(query.battle_ui.heal,0,query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking heal pop up",clickPot,20);
  1251. };
  1252. let do_heal = false;
  1253. if (pot_type=="blue" && is_front_healable.indexOf(true)>=0) {
  1254. do_heal = true;
  1255. }else if (pot_type=="green" && is_player_healable[char_id]) {
  1256. do_heal = true;
  1257. }else{
  1258. if (typeof callback == "function") {
  1259. callback();
  1260. }
  1261. }
  1262. if (do_heal) {
  1263. checkEl(query.battle_ui.heal,0,clickHeal);
  1264. }
  1265. };
  1266.  
  1267. let check_exist = setInterval(function() {
  1268. console.log("querying enemy name to appear");
  1269. if (document.querySelector("a.btn-targeting.enemy-1:not(.invisible)") !== null || document.querySelector("a.btn-targeting.enemy-2:not(.invisible)") !== null || document.querySelector("a.btn-targeting.enemy-3:not(.invisible)") !== null){
  1270. console.log("check width enemy name");
  1271. if (document.querySelector("a.btn-targeting.enemy-1:not(.invisible)").getBoundingClientRect().width>0 || document.querySelector("a.btn-targeting.enemy-2:not(.invisible)").getBoundingClientRect().width>0 || document.querySelector("a.btn-targeting.enemy-3:not(.invisible)").getBoundingClientRect().width>0){
  1272. console.log("found enemy name");
  1273. clearInterval(check_exist);
  1274. let is_quest_id_valid = false;
  1275. let is_twitter_valid = false;
  1276. try{
  1277. console.log(rep.quest_id);
  1278. if (rep.quest_id!==undefined) {
  1279. is_quest_id_valid = true;
  1280. }
  1281. }
  1282. catch(err){
  1283. console.log(err.message);
  1284. }
  1285. console.log("is_quest_id_valid:" +(is_quest_id_valid).toString());
  1286. try{
  1287. console.log(rep.twitter.monster);
  1288. if (rep.twitter.monster!==undefined) {
  1289. is_twitter_valid = true;
  1290. }
  1291. }
  1292. catch(err){
  1293. console.log(err.message);
  1294. }
  1295. console.log("is_twitter_valid:" +(is_twitter_valid).toString());
  1296. let case_battle = false;
  1297. if (is_quest_id_valid){
  1298. if (trials_id.indexOf(rep.quest_id)>=0) {
  1299. case_battle = 99;
  1300. }else{
  1301. for (let i in quests_id) {
  1302. if (rep.quest_id == quests_id[i] && case_battle === false) {
  1303. case_battle = parseInt(i)+1;
  1304. }
  1305. }
  1306. }
  1307. }
  1308. if (case_battle === false && is_twitter_valid){
  1309. for (let i in monsters_name) {
  1310. if (rep.twitter.monster==monsters_name[i] && case_battle === false) {
  1311. case_battle = parseInt(i)+1;
  1312. }
  1313. }
  1314. }
  1315. console.log("case_battle:" + case_battle.toString());
  1316. let hp = ((parseInt(rep.boss.param[0].hp) / parseInt(rep.boss.param[0].hpmax)) * 100).toString();
  1317. if (hp.indexOf(".")>=0){
  1318. hp = hp.substring(0,hp.indexOf("."));
  1319. }
  1320. battleLogic(case_battle);
  1321. }
  1322. }
  1323. }, 300);
  1324. }
  1325.  
  1326. function clickChar(param,callback=false) {
  1327. clickAndCheck("div.prt-member>div.btn-command-character>img.img-chara-command",param-1,".prt-command-chara.chara"+(param.toString()),0,my_profile+"Clicking "+battle.player.param[param-1].name,callback);
  1328. }
  1329.  
  1330. function clickBoss(boss_id,callback=false) {
  1331. const boss_id_str = (boss_id+1).toString();
  1332. if (battle.boss.param[boss_id] !== undefined || battle.boss.param[boss_id].alive === 1) {
  1333. clickAndCheck('.enemy-info>.name',boss_id,'.btn-targeting.enemy-'+boss_id_str+'.lock-on',0,my_profile+'Clicking Boss '+boss_id_str,callback);
  1334. } else {
  1335. if (typeof callback == "function") {
  1336. callback();
  1337. }
  1338. }
  1339. }
  1340.  
  1341. function raidFinish(rep,send_all_loot=false){
  1342. console.log(raidFinish.name);
  1343. reload(10);
  1344. let cmd = [];
  1345. let tracked_loot = [];
  1346. let check_timer = true;
  1347. cmd.push({"cmd":"log","level":"process","msg":message.raid.finish});
  1348.  
  1349. let all_loot = {};
  1350. let important_loot = {};
  1351. for (const i in rep.rewards.reward_list) {
  1352. if (rep.rewards.reward_list.hasOwnProperty(i)) {
  1353. const loots = rep.rewards.reward_list[i];
  1354. for (const j in loots) {
  1355. if (loots.hasOwnProperty(j)) {
  1356. const loot = loots[j];
  1357. if ( ( ['weapon','summon'].indexOf(loot.type) >= 0 ) && loot.rarity=='4') {
  1358. if (tracked_loot.indexOf(loot.name)===-1) {
  1359. tracked_loot.push(loot.name);
  1360. }
  1361. } else if (tracker_reward_weapons.indexOf(loot.name) >= 0 || tracker_reward_summons.indexOf(loot.name) >= 0 || tracker_reward_items.indexOf(loot.name) >= 0) {
  1362. if (tracked_loot.indexOf(loot.name)===-1) {
  1363. tracked_loot.push(loot.name);
  1364. }
  1365. }
  1366. if (all_loot[loot.name]===undefined) {
  1367. all_loot[loot.name] = parseInt(loot.count);
  1368. } else {
  1369. all_loot[loot.name] += parseInt(loot.count);
  1370. }
  1371. }
  1372. }
  1373. }
  1374. }
  1375. if (send_all_loot) {
  1376. important_loot = all_loot;
  1377. } else {
  1378. for (const loot in all_loot) {
  1379. if (all_loot.hasOwnProperty(loot)) {
  1380. const qty = all_loot[loot];
  1381. if (tracked_loot.indexOf(loot)>=0) {
  1382. important_loot[loot] = qty;
  1383. }
  1384. }
  1385. }
  1386. }
  1387. console.log(important_loot);
  1388. if (Object.keys(important_loot).length > 0) {
  1389. cmd.push({"cmd":"reward","payload":important_loot});
  1390. cmd.push({"cmd":"log","level":"summary","msg":Object.keys(important_loot).length});
  1391. }
  1392.  
  1393. if (tracked_item !== false){
  1394. let data_track = my_profile+"Current Status:";
  1395. let temp_str;
  1396. for (let item in tracked_item){
  1397. if (tracked_item.hasOwnProperty(item)) {
  1398. let item_qty = parseInt(tracked_item[item].number);
  1399. let drop_qty = 0;
  1400. if (all_loot[tracked_item[item].name] !== undefined) {
  1401. drop_qty = all_loot[tracked_item[item].name];
  1402. }
  1403. temp_str = "\n- "+tracked_item[item].name+": "+(item_qty + drop_qty).toString();
  1404. if (all_loot[tracked_item[item].name] !== undefined) {
  1405. temp_str += ' ( +'+(drop_qty).toString()+' )';
  1406. }
  1407. data_track += temp_str;
  1408. }
  1409. }
  1410. cmd.push({"cmd":"log","level":"summary","msg":data_track,"split":0});
  1411. }
  1412. if (check_timer){
  1413. cmd.push({"cmd":"check_timer"});
  1414. }
  1415. xhr.open('POST', server);
  1416. xhr.send(JSON.stringify(cmd));
  1417. let gotoMain = function() {gotoHash("main");};
  1418. checkEl(".mask",0,gotoMain);
  1419. }
  1420.  
  1421. function missionComplete() {
  1422. clearInterval(reload_counter);
  1423. let cmd = [];
  1424. cmd.push({"cmd":"log","level":"notif","msg":my_profile+"Objective cleared. Mission complete. @everyone","mention_everyone":true});
  1425. cmd.push({"cmd":"log","level":"summary","msg":my_profile+"Objective cleared. Mission complete."});
  1426. cmd.push({"cmd":"hotkey","keys":["ctrl","w"]});
  1427. xhr.open('POST', server);
  1428. xhr.send(JSON.stringify(cmd));
  1429. }
  1430.  
  1431. function init() {
  1432. "use strict";
  1433. console.log(init.name);
  1434. reload(5);
  1435. setDebug();
  1436. listenNetwork();
  1437. let checkBody = setInterval(function() {
  1438. console.log(checkBody.name);
  1439. if(document.body !== null){
  1440. clearInterval(checkBody);
  1441. if(document.body.children[0].tagName == "DIV"){
  1442. // reload(30);
  1443. checkError();
  1444. }else{
  1445. console.log("DOM Error");
  1446. reloadNow();
  1447. }
  1448. }
  1449. }, 300);
  1450. }