NEET Lib

NEET Bot Library

当前为 2019-11-15 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/383201/749692/NEET%20Lib.js

  1. // ==UserScript==
  2. // @name NEET Lib
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.5.3
  5. // @description NEET Bot Library
  6. // @author eterNEETy
  7. // @match http://game.granbluefantasy.jp/
  8. // @grant none
  9. // @namespace https://gf.qytechs.cn/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. 1.3.2:
  28. - missionComplete(cmd=[]);
  29.  
  30. 1.4.0:
  31. - lot of skill changes
  32. 1.4.1:
  33. - changed scrollTo to scroll_To
  34. 1.4.2:
  35. - changed getCoord, added auto scroll
  36.  
  37. 1.5.0:
  38. - replaced all references
  39. - changed 'message' from not defined to defined (let)
  40. - changed 'getMessage' to 'updateMessage'
  41. - changed 'battleLogic' from function to var
  42. - changed 'listenNetwork' from function to var
  43. 1.5.1:
  44. - added a lot of support changes
  45. 1.5.2:
  46. - added cnt_error "An error has occurred. Return to the Home screen and try again. If this issue continues, please use the contact form."
  47. 1.5.3:
  48. - added skin summon support
  49.  
  50. */
  51.  
  52.  
  53. // environment info
  54. const xhr = new XMLHttpRequest(),
  55. server = 'http://localhost:2487',
  56. margin = {'top':91,'left':0},
  57. game_url = 'http://game.granbluefantasy.jp/';
  58.  
  59. let debug = true,
  60. reload_counter;
  61.  
  62. let zoom = 1;
  63.  
  64. let is_host = 'false';
  65. let battle;
  66. let is_wiped = true;
  67. let discord_mention = '';
  68. let abi_special_case = false;
  69.  
  70. let quests_id = [], monsters = [], monsters_name = [];
  71. const recovery_items = ['Elixir','Half Elixir','Soul Balm','Soul Berry'];
  72. let reloadable_skill = ['Four-Sky\'s Sorrow', 'Thunder Raid'];
  73. let tracker_reward_weapons = [];
  74. let tracker_reward_summons = [];
  75. let tracker_reward_items = [recovery_items[0], recovery_items[1], recovery_items[2], recovery_items[3],'Gold Brick','Damascus Grain','Silver Centrum'];
  76.  
  77.  
  78. const huanglong = {'name':'Huanglong', 'star':3},
  79. // providence
  80. lucifer = {'name':'Lucifer', 'star':5},
  81. bahamut = {'name':'Bahamut', 'star':5},
  82. // regallia
  83. shiva = {'name':'Shiva', 'star':3},
  84. shiva0 = {'name':'Shiva', 'star':0},
  85. europa = {'name':'Europa', 'star':3},
  86. europa0 = {'name':'Europa', 'star':0},
  87. alex = {'name':'Godsworn Alexiel', 'star':3},
  88. alex0 = {'name':'Godsworn Alexiel', 'star':0},
  89. grimnir = {'name':'Grimnir', 'star':3},
  90. grimnir0 = {'name':'Grimnir', 'star':0},
  91. // optimus
  92. agni = {'name':'Agni', 'star':4},
  93. agni3 = {'name':'Agni', 'star':3},
  94. agni0 = {'name':'Agni', 'star':0},
  95. varuna = {'name':'Varuna', 'star':4},
  96. varuna3 = {'name':'Varuna', 'star':3},
  97. varuna0 = {'name':'Varuna', 'star':0},
  98. titan = {'name':'Titan', 'star':4},
  99. titan3 = {'name':'Titan', 'star':3},
  100. titan0 = {'name':'Titan', 'star':0},
  101. zephyrus = {'name':'Zephyrus', 'star':4},
  102. zephyrus3 = {'name':'Zephyrus', 'star':3},
  103. zephyrus0 = {'name':'Zephyrus', 'star':0},
  104. zeus = {'name':'Zeus', 'star':4},
  105. zeus3 = {'name':'Zeus', 'star':3},
  106. zeus0 = {'name':'Zeus', 'star':0},
  107. hades = {'name':'Hades', 'star':4},
  108. hades3 = {'name':'Hades', 'star':3},
  109. hades0 = {'name':'Hades', 'star':0},
  110. // magna
  111. colossus = {'name':'Colossus Omega', 'star':4},
  112. leviathan = {'name':'Leviathan Omega', 'star':4},
  113. yggdrasil = {'name':'Yggdrasil Omega', 'star':4},
  114. tiamat = {'name':'Tiamat Omega', 'star':4},
  115. luminiera = {'name':'Luminiera Omega', 'star':4},
  116. celeste = {'name':'Celeste Omega', 'star':4},
  117. //
  118. raphael = {'name':'Raphael', 'star':3},
  119. raphael0 = {'name':'Raphael', 'star':0},
  120. gabriel = {'name':'Gabriel', 'star':3},
  121. gabriel0 = {'name':'Gabriel', 'star':0},
  122. uriel = {'name':'Uriel', 'star':3},
  123. // ele
  124. poseidon = {'name':'Poseidon', 'star':3},
  125. poseidon0 = {'name':'Poseidon', 'star':0},
  126. //
  127. bonito = {'name':'Bonito', 'star':4},
  128. // misc
  129. kaguya = {'name':'Kaguya', 'star':3},
  130. kaguya0 = {'name':'Kaguya', 'star':0},
  131. white_rabbit = {'name':'White Rabbit', 'star':3},
  132. black_rabbit = {'name':'Black Rabbit', 'star':3};
  133. const leech_summons = [kaguya,kaguya0,white_rabbit,black_rabbit],
  134. ele_water_summons = [poseidon,europa,poseidon0,europa0,bonito,gabriel,gabriel0];
  135.  
  136. // const game variable
  137. // const trials_id = ["990011","990021","990031","990041","990051","990061","990071"],
  138. // select_summon_path = "supporter/";
  139. const trial_id = '990011',
  140. select_summon_path = 'supporter/';
  141. // path
  142. let path = {
  143. 'main': '',
  144. 'item':'#item',
  145. 'quest':'#quest',
  146. 'support':'#quest/supporter/',
  147. 'assist':'#quest/assist',
  148. 'unclaimed':'#quest/assist/unclaimed',
  149. 'trial':'#quest/supporter/'+trial_id+'/17',
  150. };
  151.  
  152. // element dom query selector
  153. let skill_char = '#prt-command-top > div > div > div.lis-character';
  154. let skill_abi = '.btn-command-character > div.prt-ability-state > div.lis-ability-state.ability';
  155. let query = {
  156. 'battle_ui': {
  157. 'skill': {
  158. 'char1': {
  159. 'skill1': skill_char + '0' + skill_abi + '1',
  160. 'skill2': skill_char + '0' + skill_abi + '2',
  161. 'skill3': skill_char + '0' + skill_abi + '3',
  162. 'skill4': skill_char + '0' + skill_abi + '4',
  163. },
  164. 'char2': {
  165. 'skill1': skill_char + '1' + skill_abi + '1',
  166. 'skill2': skill_char + '1' + skill_abi + '2',
  167. 'skill3': skill_char + '1' + skill_abi + '3',
  168. 'skill4': skill_char + '1' + skill_abi + '4',
  169. },
  170. 'char3': {
  171. 'skill1': skill_char + '2' + skill_abi + '1',
  172. 'skill2': skill_char + '2' + skill_abi + '2',
  173. 'skill3': skill_char + '2' + skill_abi + '3',
  174. 'skill4': skill_char + '2' + skill_abi + '4',
  175. },
  176. 'char4': {
  177. 'skill1': skill_char + '3' + skill_abi + '1',
  178. 'skill2': skill_char + '3' + skill_abi + '2',
  179. 'skill3': skill_char + '3' + skill_abi + '3',
  180. 'skill4': skill_char + '3' + skill_abi + '4',
  181. },
  182. },
  183. 'skill_pop_up': {
  184. 'char1': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character0.btn-command-character > img',
  185. 'char2': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character1.btn-command-character > img',
  186. 'char3': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character2.btn-command-character > img',
  187. 'char4': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character3.btn-command-character > img',
  188. 'char5': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character4.btn-command-character > img',
  189. 'char6': 'div.pop-usual.pop-select-member > div.prt-popup-body > div.prt-wrapper > div.prt-character > div.lis-character5.btn-command-character > img',
  190. },
  191. 'ougi': '.btn-lock',
  192. 'toggle_ougi': {
  193. true: '.lock0',
  194. false: '.lock1',
  195. },
  196. 'char_ico': '.prt-party>.prt-member>.btn-command-character>img.img-chara-command',
  197. 'summon_panel': '.prt-summon-list>.prt-list-top.btn-command-summon',
  198. 'chat':'.btn-chat.comment.display-on',
  199. 'chat_pop_up': {
  200. 'dialog':'.txt-chat-pop',
  201. },
  202. 'heal':'#prt-sub-command-group>.btn-temporary',
  203. 'heal_pop_up': {
  204. 'green': '.lis-item.item-small',
  205. 'blue': '.lis-item.item-large',
  206. 'Green Potion': '.lis-item.item-small',
  207. 'Blue Potion': '.lis-item.item-large',
  208. 'Support Potion': '.lis-item.btn-event-item[item-id="1"]',
  209. 'Clarity Herb': '.lis-item.btn-event-item[item-id="2"]',
  210. 'Revival Potion': '.lis-item.btn-event-item[item-id="3"]',
  211. 'use': '.pop-usual.pop-raid-item.pop-show>.prt-popup-footer>.btn-usual-use',
  212. 'cancel': '.pop-usual.pop-raid-item.pop-show>.prt-popup-footer>.btn-usual-cancel',
  213. },
  214. 'trial_pop_up': {
  215. 'close': '.pop-usual.pop-trialbattle-notice.pop-show>.prt-popup-footer>.btn-usual-close',
  216. },
  217. 'backup_pop_up': {
  218. 'request': '.pop-usual.pop-start-assist.pop-show>.prt-popup-footer>.btn-usual-text',
  219. 'cancel': '.pop-usual.pop-start-assist.pop-show>.prt-popup-footer>.btn-usual-cancel',
  220. },
  221. 'button': {
  222. 'assist': '.prt-multi-buttons>.btn-assist',
  223. },
  224. },
  225. 'assist_ui': {
  226. 'tab_id': '#tab-id',
  227. 'tab_multi': '#tab-multi',
  228. 'tab_event': '#tab-event',
  229. 'unclaimed': '.btn-unclaimed',
  230. },
  231. 'poker': {
  232. 'canvas': '#canv',
  233. 'deal': '.prt-start',
  234. 'ok': '.prt-ok',
  235. 'yes': '.prt-yes',
  236. 'no': '.prt-no',
  237. 'low': '.prt-double-select>.prt-low-shine',
  238. 'high': '.prt-double-select>.prt-high-shine',
  239. },
  240. 'ok':'.btn-usual-ok',
  241. };
  242.  
  243. let my_profile = '';
  244. function updateMessage(pilot) {
  245. const message = {
  246. "raid" : {
  247. "panel" : {
  248. "open" : pilot+"Opening quest/raid panel",
  249. "pick" : pilot+"Picking quest/raid difficulties",
  250. },
  251. "select_party" : pilot+"Selecting party",
  252. "finish" : pilot+"Raid finished",
  253. "trial" : {
  254. "close_pop_up" : pilot+"In trial, closing pop up",
  255. "open_menu" : pilot+ "In trial, click menu",
  256. "retreat" : pilot+ "In trial, click retreat",
  257. "ok" : pilot+ "In trial, click ok",
  258. "end" : pilot+"Retreated from trial, back to main raid",
  259. }
  260. },
  261. "summon" : {
  262. "select" : pilot+"Selecting summon",
  263. "pick_tab" : pilot+"Clicking summon element tab",
  264. "not_found" : pilot+"Support summon not found, going to trial",
  265. },
  266. "replenish" : {
  267. "elixir" : {
  268. "half_elixir" : {
  269. "use" : pilot+"Not enough AP, using half elixir",
  270. "used" : pilot+"Half elixir used",
  271. }
  272. },
  273. "soul" : {
  274. "soul_berry" : {
  275. "use" : pilot+"Not enough EP, using soul berry",
  276. "used" : pilot+"soul berry used",
  277. }
  278. }
  279. },
  280. "ok" : pilot+"Clicking ok",
  281. };
  282. return message;
  283. }
  284. let message = updateMessage(my_profile);
  285.  
  286. // general item variable
  287. let tracked_item = false;
  288.  
  289.  
  290.  
  291. function reloadNow() {
  292. console.log(reloadNow.name);
  293. xhr.open('POST', server);
  294. xhr.send(JSON.stringify([{'cmd':'press','key':'f5'}]));
  295. window.location.reload();
  296. }
  297.  
  298. function reload(mod_value=1) {
  299. clearInterval(reload_counter);
  300. let current_path = window.location.hash;
  301. let count = 1;
  302. reload_counter = setInterval(function() {
  303. if(window.location.hash != current_path){
  304. clearInterval(reload_counter);
  305. }
  306. console.log('reloading in '+(mod_value-count).toString());
  307. if (count%mod_value===0){
  308. clearInterval(reload_counter);
  309. reloadNow();
  310. }
  311. count += 1;
  312. }, 1000);
  313. }
  314.  
  315. function setDebug() {
  316. if(!debug){
  317. console.log('DEBUG is turned OFF');
  318. if(!window.console) window.console = {};
  319. let methods = ['log', 'debug', 'warn', 'info'];
  320. for(let i=0;i<methods.length;i++){
  321. console[methods[i]] = function(){};
  322. }
  323. }
  324. }
  325.  
  326. function readBody(xhr) {
  327. let data;
  328. if (!xhr.responseType || xhr.responseType === 'text') {
  329. data = xhr.responseText;
  330. } else if (xhr.responseType === 'document') {
  331. data = xhr.responseXML;
  332. } else {
  333. data = xhr.response;
  334. }
  335. return data;
  336. }
  337.  
  338. function gotoHash(key){
  339. let hash_path;
  340. if (path[key] !== undefined) {
  341. hash_path = path[key];
  342. }else{
  343. if (key.indexOf('#')!==0) {
  344. hash_path = '#'+key;
  345. }
  346. }
  347. window.location.href = game_url + hash_path;
  348. }
  349.  
  350. function scroll_To(query,qid=0) {
  351. document.querySelectorAll(query)[qid].scrollIntoViewIfNeeded();
  352. }
  353.  
  354. function checkExist(query,qid=0) {
  355. let el_exist = false;
  356. if (document.querySelectorAll(query).length > qid){
  357. if (document.querySelectorAll(query)[qid].getBoundingClientRect().width > 0 && document.querySelectorAll(query)[qid].getBoundingClientRect().height > 0) {
  358. el_exist = true;
  359. }
  360. }
  361. return el_exist;
  362. }
  363.  
  364. function checkEl(query,qid=0,callback=false) {
  365. let old_top = -1;
  366. let old_left = -1;
  367. let loop_checkEl = setInterval(function() {
  368. console.log(checkEl.name + " " + query + "[" + qid + "]");
  369. if (checkExist(query,qid)) {
  370. if (old_top==document.querySelectorAll(query)[qid].getBoundingClientRect().top && old_left==document.querySelectorAll(query)[qid].getBoundingClientRect().left) {
  371. clearInterval(loop_checkEl);
  372. if (typeof callback == "function") {
  373. callback();
  374. }
  375. }else{
  376. old_top = document.querySelectorAll(query)[qid].getBoundingClientRect().top;
  377. old_left = document.querySelectorAll(query)[qid].getBoundingClientRect().left;
  378. }
  379. }
  380. }, 200);
  381. }
  382.  
  383. function checkEls(queries,callback=false) {
  384. let exist_result;
  385. let loop_checkEls = setInterval(function() {
  386. exist_result = [];
  387. for (let i in queries) {
  388. console.log(checkEls.name + " " + queries[i].query + "[" + queries[i].qid + "]");
  389. exist_result.push(checkExist(queries[i].query,queries[i].qid));
  390. }
  391. if (exist_result.indexOf(false)===-1) {
  392. clearInterval(loop_checkEls);
  393. if (typeof callback == "function") {
  394. callback();
  395. }
  396. }
  397. }, 300);
  398. }
  399.  
  400. function checkElsOR(queries,callback=false) {
  401. let exist_result;
  402. let loop_checkEls = setInterval(function() {
  403. exist_result = [];
  404. for (let i in queries) {
  405. console.log(checkElsOR.name + " " + queries[i].query + "[" + queries[i].qid + "]");
  406. exist_result.push(checkExist(queries[i].query,queries[i].qid));
  407. }
  408. if (exist_result.indexOf(true)>=0) {
  409. clearInterval(loop_checkEls);
  410. if (typeof callback == "function") {
  411. callback();
  412. }
  413. }
  414. }, 300);
  415. }
  416.  
  417. function checkError() {
  418. let q_cnt_error = ".cnt-error";
  419. let q_pop_up = ".pop-usual.common-pop-error.pop-show";
  420. let q_abi_pop_up = ".pop-usual.pop-raid-ability-error.pop-show";
  421. let check_error = setInterval(function() {
  422. console.log(checkError.name);
  423. if (checkExist(q_pop_up,0) || checkExist(q_cnt_error,0) || checkExist(q_abi_pop_up,0)) {
  424. let cmd = [];
  425. console.log("error_found");
  426. let do_reload = false;
  427. let level = "notif";
  428. let msg = "Uncatagorized error found";
  429. // let msg = "Connection error, refreshing disabled"
  430. if (checkExist(q_cnt_error,0)) {
  431. if (checkExist('#wrapper > div.contents > div.cnt-error > div.prt-frame > div',0)) {
  432. if (checkExist('#wrapper > div.contents > div.cnt-error > div.prt-frame > div > p',0)) {
  433. do_reload = true;
  434. let msg_str = document.querySelector('#wrapper > div.contents > div.cnt-error > div.prt-frame > div > p').innerHTML;
  435. msg_str = msg_str.replace(/<br>/g,' ').replace(/<\/br>/g,' ').trim().replace(/\s{2,}/g, ' ').trim();
  436. msg = my_profile + msg_str +' Reloading.';
  437. level = "notif";
  438. }
  439. }
  440. } else if (checkExist(q_abi_pop_up,0)) {
  441. do_reload = true;
  442. msg = my_profile + document.querySelector(q_abi_pop_up+">.prt-popup-body>.txt-popup-body").innerHTML;
  443. level = "process";
  444. } else {
  445. if (checkExist(q_pop_up+">.prt-popup-header",0)) {
  446. if (document.querySelector(q_pop_up+">.prt-popup-header").innerHTML=="Access Verification") {
  447. clearInterval(reload_counter);
  448. clearInterval(check_error);
  449. msg = my_profile+"Captcha detected. " + discord_mention;
  450. console.log("Captcha detected");
  451. }else if (document.querySelector(q_pop_up+">.prt-popup-header").innerHTML=="エラー") {
  452. if (checkExist(q_pop_up+">.prt-popup-body>.txt-popup-body>div",0)) {
  453. if (typeof document.querySelector(q_pop_up+">.prt-popup-body>.txt-popup-body>div").innerHTML == "string") {
  454. if (document.querySelector(q_pop_up+">.prt-popup-body>.txt-popup-body>div").innerHTML.indexOf("Network Error")>=0) {
  455. clearInterval(reload_counter);
  456. console.log("Error connection");
  457. do_reload = true;
  458. msg = my_profile+"Error connection, reloading";
  459. level = "process";
  460. }
  461. }
  462. }
  463. }
  464. }
  465. if (checkExist(q_pop_up+">.prt-popup-body>.txt-popup-body",0)) {
  466. if (document.querySelector(q_pop_up+">.prt-popup-body>.txt-popup-body").innerHTML=="Check your pending battles.") {
  467. console.log("check raid");
  468. level = "process";
  469. msg = my_profile+"Check your pending battle";
  470. clickEl(".prt-popup-footer>.btn-usual-ok",0,my_profile+"Clicking ok pop up pending battles");
  471. }
  472. }
  473. }
  474. if (do_reload){
  475. cmd.push({"cmd":"press","key":"f5"});
  476. }
  477. cmd.push({"cmd":"log","level":level,"msg":msg});
  478. xhr.open('POST', server);
  479. xhr.send(JSON.stringify(cmd));
  480. if (do_reload){
  481. window.location.reload();
  482. }
  483. }
  484. }, 5000);
  485. }
  486.  
  487. function getCoord(el){
  488. zoom = parseInt(document.getElementById("mobage-game-container").style.zoom);
  489. let x, y, output;
  490. let pos_el = el.getBoundingClientRect();
  491. if (pos_el.top >= 0 && pos_el.bottom <= window.innerHeight) {
  492. if (pos_el.width>0 && pos_el.height>0) {
  493. x = (pos_el.width / 2) + pos_el.left;
  494. y = (pos_el.height / 2) + pos_el.top;
  495. if(pos_el.width>40){
  496. x += Math.floor(Math.random() * 41)-20;
  497. }else if(pos_el.width>20){
  498. x += Math.floor(Math.random() * 21)-10;
  499. }else if(pos_el.width>10){
  500. x += Math.floor(Math.random() * 11)-5;
  501. }
  502. if(pos_el.height>10){
  503. y += Math.floor(Math.random() * 11)-5;
  504. }
  505. output = [(x*zoom)+margin.left,(y*zoom)+margin.top];
  506. }else{
  507. output = 0;
  508. }
  509. return output;
  510. } else {
  511. el.scrollIntoViewIfNeeded();
  512. return getCoord(el);
  513. }
  514. }
  515.  
  516. function getMarginCoord(query,qid){
  517. let el = document.querySelectorAll(query)[qid].getBoundingClientRect();
  518. return {"top":el.top+margin.top,"left":el.left+margin.left};
  519. }
  520.  
  521. function clickNow(query,qid=0,msg=my_profile+"clickNow called",callback=false){
  522. let el = document.querySelectorAll(query)[qid];
  523. let output = false;
  524. if (checkExist(query,qid)) {
  525. output = true;
  526. let cmd = [];
  527. cmd.push({"cmd":"clickIt","param":getCoord(el)});
  528. cmd.push({"cmd":"log","level":"process","msg":msg});
  529. xhr.open("POST", server);
  530. xhr.send(JSON.stringify(cmd));
  531. if (typeof callback == "function") {
  532. callback();
  533. }
  534. }
  535. return output;
  536. }
  537.  
  538. function clickEl(query,qid=0,msg=my_profile+"clickEl called",callback=false){
  539. let init_clickEl = function() {
  540. clickNow(query,qid,msg,callback);
  541. };
  542. checkEl(query,qid,init_clickEl);
  543. }
  544.  
  545. function clickObject(obj){
  546. if (obj == "ok"){
  547. clickEl(".btn-usual-ok",0,message.ok);
  548. }
  549. }
  550.  
  551. function clickAndNegCheck(query,qid=0,msg="clickAndNegCheck called",callback=false,ticks=5){
  552. let old_href = window.location.href;
  553. let old_top = -1;
  554. let old_left = -1;
  555. let match = ticks-1;
  556. let str_clickAndNegCheck = clickAndNegCheck.name + ", el: " + query + "["+(qid.toString())+"] \n- match = ";
  557. let init_clickAndNegCheck = function() {
  558. let loop_clickAndNegCheck = setInterval(function() {
  559. console.log(str_clickAndNegCheck+(match.toString()));
  560. if (!(checkExist(query,qid))) {
  561. clearInterval(loop_clickAndNegCheck);
  562. if (typeof callback == "function") {
  563. callback();
  564. }
  565. }else if (old_href != window.location.href) {
  566. clearInterval(loop_clickAndNegCheck);
  567. }else{
  568. if (checkExist(query,qid)) {
  569. if (old_top==document.querySelectorAll(query)[qid].getBoundingClientRect().top && old_left==document.querySelectorAll(query)[qid].getBoundingClientRect().left) {
  570. if (match % ticks == 0) {
  571. clickNow(query,qid,msg);
  572. }
  573. match += 1;
  574. }else{
  575. old_top = document.querySelectorAll(query)[qid].getBoundingClientRect().top;
  576. old_left = document.querySelectorAll(query)[qid].getBoundingClientRect().left;
  577. }
  578. }
  579. }
  580. }, 100);
  581. };
  582. checkEl(query,qid,init_clickAndNegCheck);
  583. }
  584.  
  585. function clickAndCheck(query1,qid1=0,query2,qid2=0,msg="clickAndCheck called",callback=false,ticks=5){
  586. let old_href = window.location.href;
  587. let old_top = -1;
  588. let old_left = -1;
  589. let match = ticks-1;
  590. let str_clickAndCheck = clickAndCheck.name + ", check: " + query2 + "["+(qid2.toString())+"], click: " + query1 + "["+(qid1.toString())+"] \n- match = ";
  591. let loop_clickAndCheck = setInterval(function() {
  592. console.log(str_clickAndCheck+(match.toString()));
  593. if (checkExist(query2,qid2)) {
  594. clearInterval(loop_clickAndCheck);
  595. if (typeof callback == "function") {
  596. callback();
  597. }
  598. }else if (old_href != window.location.href) {
  599. clearInterval(loop_clickAndCheck);
  600. }else{
  601. if (checkExist(query1,qid1)) {
  602. if (old_top==document.querySelectorAll(query1)[qid1].getBoundingClientRect().top && old_left==document.querySelectorAll(query1)[qid1].getBoundingClientRect().left) {
  603. if (match % ticks == 0) {
  604. clickNow(query1,qid1,msg);
  605. }
  606. match += 1;
  607. }else{
  608. old_top = document.querySelectorAll(query1)[qid1].getBoundingClientRect().top;
  609. old_left = document.querySelectorAll(query1)[qid1].getBoundingClientRect().left;
  610. }
  611. }
  612. }
  613. }, 100);
  614. }
  615.  
  616. function popUpNotEnough(rep) {
  617. const query = ".btn-use-full.index-1",
  618. qid = 0,
  619. msg = message.replenish.elixir.half_elixir.use;
  620. let cmd = [], coordinate, consumable_data;
  621. consumable_data = my_profile+"Consumable Status:";
  622. for (let i = 0; i < rep.length; i++) {
  623. consumable_data += ("\n- "+rep[i].name+": "+rep[i].number);
  624. }
  625. let init_popUpNotEnough = function() {
  626. coordinate = getCoord(document.querySelectorAll(query)[qid]);
  627. if (coordinate!==0){
  628. cmd.push({"cmd":"clickIt","param":coordinate});
  629. cmd.push({"cmd":"log","level":"process","msg":msg});
  630. cmd.push({"cmd":"log","level":"summary","msg":consumable_data,"split":0});
  631. xhr.open('POST', server);
  632. xhr.send(JSON.stringify(cmd));
  633. }
  634. };
  635. checkEl(query,qid,init_popUpNotEnough);
  636.  
  637. }
  638.  
  639.  
  640. // function clickAndCheckSkill(query,qid=0,msg="clickAndCheckSkill called",callback=false,special_case=false){
  641. // console.log(clickAndCheckSkill.name);
  642. // console.log(callback);
  643. // console.log(query);
  644. // console.log(qid);
  645. // let old_class = document.querySelectorAll(query)[qid].parentNode.classList[0];
  646. // console.log(old_class);
  647. // let loop_clickAndCheckSkill = setInterval(function() {
  648. // console.log(loop_clickAndCheckSkill.name + " " + query + "[" + qid + "]");
  649. // 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){
  650. // clearInterval(loop_clickAndCheckSkill);
  651. // console.log(clickAndCheckSkill.name + " case normal");
  652. // if (typeof callback == "function") {
  653. // callback();
  654. // }
  655. // // Bea skill
  656. // }else if(special_case===1 && document.querySelectorAll(query)[qid].parentNode.classList[0] != old_class){
  657. // clearInterval(loop_clickAndCheckSkill);
  658. // console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  659. // if (typeof callback == "function") {
  660. // callback();
  661. // }
  662. // // Out of sight & sage of eternity
  663. // }else if(special_case===2){
  664. // let do_click = true;
  665. // console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  666. // let popup_query = "#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header";
  667. // if (checkExist(popup_query,0)) {
  668. // if (document.querySelector("#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header").innerHTML == "Use Skill"){
  669. // clearInterval(loop_clickAndCheckSkill);
  670. // do_click = false;
  671. // if (typeof callback == "function") {
  672. // callback();
  673. // }
  674. // }
  675. // }
  676. // if (do_click) {
  677. // if (checkExist(query,qid)) {
  678. // clickNow(query,qid,msg);
  679. // }
  680. // }
  681. // }else{
  682. // if (checkExist(query,qid)) {
  683. // clickNow(query,qid,msg);
  684. // }
  685. // }
  686.  
  687. // }, 500);
  688. // }
  689.  
  690. function clickSkill(cid,abi_id,callback=false){
  691. console.log(clickSkill.name+', cid: '+cid.toString()+', ability: '+abi_id.toString());
  692. let query = ".prt-command-chara.chara"+((cid+1).toString())+">div>div>div>.img-ability-icon";
  693. let qid = abi_id;
  694. let char = battle.player.param[cid].name;
  695. let msg = my_profile+"Clicking "+char+" skill"+((abi_id+1).toString());
  696. let old_class = document.querySelectorAll(query)[qid].parentNode.classList[0];
  697. let abi_obj = Object.values(battle.ability).find(x => x.pos === cid);
  698. let abi_name = abi_obj.list[abi_id+1][0]['ability-name'];
  699. let loop_clickSkill = setInterval(function() {
  700. console.log("loop_clickSkill " + query + "[" + qid + "]");
  701. 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){
  702. clearInterval(loop_clickSkill);
  703. console.log('case normal');
  704. if (typeof callback == "function") {
  705. callback();
  706. }
  707. } else if (abi_name === 'Runeweaving') {
  708. console.log('case Runeweaving');
  709. let do_click = true;
  710. let popup_query = '#wrapper > div.contents > div.pop-usual.pop-ability-mark > div.prt-popup-header';
  711. if (checkExist(popup_query,0)) {
  712. if (document.querySelector(popup_query).innerHTML == 'Use Skill'){
  713. clearInterval(loop_clickSkill);
  714. do_click = false;
  715. let error_special_case = true;
  716. let error_msg = 'Error skill: ';
  717. let q_invoke = '.lis-ability-mark';
  718. let q_rune = '>.lis-ability-frame';
  719.  
  720. const invoke = {'fire':'.mark1', 'water':'.mark2', 'earth':'.mark3', 'wind':'.mark4'};
  721.  
  722. if (abi_special_case === false){
  723. error_msg = 'abi_special_case is false.';
  724. } else {
  725. if (typeof abi_special_case === 'object') {
  726. if (abi_special_case.hasOwnProperty('invoke')) {
  727. if (typeof abi_special_case.invoke === 'object') {
  728. if (abi_special_case.invoke.length === 2) {
  729. if (invoke.hasOwnProperty(abi_special_case.invoke[0]) && invoke.hasOwnProperty(abi_special_case.invoke[1])) {
  730. error_special_case = false;
  731. } else {
  732. error_msg = 'abi_special_case.invoke value is invalid.';
  733. }
  734. } else {
  735. error_msg = 'abi_special_case.invoke length is invalid.';
  736. }
  737. } else {
  738. error_msg = 'abi_special_case.invoke type is invalid.';
  739. }
  740. }
  741. } else {
  742. error_msg = 'abi_special_case object \'invoke\' not found.';
  743. }
  744. }
  745. console.log('error_special_case: '+error_special_case);
  746. console.log(error_msg);
  747. if (error_special_case) {
  748. let cmd = [];
  749. cmd.push({"cmd":"log","level":"notif","msg":my_profile+error_msg+discord_mention});
  750. xhr.open('POST', server);
  751. xhr.send(JSON.stringify(cmd));
  752. } else {
  753. let q_next_rune;
  754. if (abi_special_case.invoke[0] === abi_special_case.invoke[1]) {
  755. q_next_rune = '.first.second';
  756. } else {
  757. q_next_rune = '.second:not(.first)';
  758. }
  759. let q_cast = '#wrapper > div.contents > div.pop-usual.pop-ability-mark > div.prt-popup-footer > div.btn-usual-text';
  760. let click_cast = function () {clickAndNegCheck(q_cast,0,my_profile+'Clicking cast',callback);};
  761. let next_rune = function () {clickAndCheck(q_invoke+invoke[abi_special_case.invoke[1]]+q_rune,0,q_invoke+invoke[abi_special_case.invoke[1]]+q_next_rune,0,my_profile+'Clicking second rune: '+abi_special_case.invoke[1],click_cast);};
  762. clickAndCheck(q_invoke+invoke[abi_special_case.invoke[0]]+q_rune,0,q_invoke+invoke[abi_special_case.invoke[0]]+'.first:not(.second)',0,my_profile+'Clicking first rune: '+abi_special_case.invoke[0],next_rune);
  763. }
  764.  
  765. // if (typeof callback == "function") {
  766. // callback();
  767. // }
  768. }
  769. }
  770. if (do_click) {
  771. if (checkExist(query,qid)) {
  772. clickNow(query,qid,msg);
  773. }
  774. }
  775. // // Bea skill
  776. // }else if(special_case===1 && document.querySelectorAll(query)[qid].parentNode.classList[0] != old_class){
  777. // clearInterval(loop_clickAndCheckSkill);
  778. // console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  779. // if (typeof callback == "function") {
  780. // callback();
  781. // }
  782.  
  783. // // Out of sight & sage of eternity
  784. // }else if(special_case===2){
  785. // let do_click = true;
  786. // console.log(clickAndCheckSkill.name + " case " + special_case.toString());
  787. // let popup_query = "#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header";
  788. // if (checkExist(popup_query,0)) {
  789. // if (document.querySelector("#wrapper > div.contents > div.pop-usual.pop-select-member > div.prt-popup-header").innerHTML == "Use Skill"){
  790. // clearInterval(loop_clickAndCheckSkill);
  791. // do_click = false;
  792. // if (typeof callback == "function") {
  793. // callback();
  794. // }
  795. // }
  796. // }
  797. // if (do_click) {
  798. // if (checkExist(query,qid)) {
  799. // clickNow(query,qid,msg);
  800. // }
  801. // }
  802. } else {
  803. console.log('case normal');
  804. if (checkExist(query,qid)) {
  805. clickNow(query,qid,msg);
  806. }
  807. }
  808.  
  809. }, 500);
  810. }
  811.  
  812.  
  813.  
  814. function useSkills(cid, skill_list, callback=false) {
  815. let char_id = cid+1;
  816. console.log(useSkills.name);
  817. if (skill_list.length>0) {
  818. console.log(useSkills.name + ", cid: "+cid+", ability: " + (skill_list[0].toString()));
  819. let new_skill_list = Object.values(skill_list);
  820. new_skill_list.splice(0,1);
  821. let abi_id = parseInt(skill_list[0])-1;
  822. let next_skill = function(){useSkills(cid, new_skill_list, callback);};
  823. 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){
  824. // 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);
  825. clickSkill(cid,abi_id,next_skill);
  826. }else{
  827. if (typeof callback == "function") {
  828. next_skill();
  829. }
  830. }
  831. } else {
  832. if (typeof callback == "function") {
  833. callback();
  834. }
  835. }
  836. }
  837.  
  838. function usePot(pot_type, cid=false, callback=false) {
  839. console.log(usePot.name);
  840. console.log(cid);
  841. let do_click_heal = false;
  842. let front_cid = false;
  843. let player_stats = {
  844. 'need_heal': [],
  845. 'front_need_heal': [],
  846. 'need_clear': [],
  847. 'need_revive': [],
  848. };
  849. for (const i in battle.player.param) {
  850. if (battle.player.param.hasOwnProperty(i)) {
  851. const player_obj = battle.player.param[i];
  852. player_stats.need_revive.push(player_obj.alive === 1);
  853. let player_need_clear = false;
  854. if (player_obj.alive === 1) {
  855. player_stats.need_heal.push(player_obj.hpmax - player_obj.hp !== 0);
  856. if (player_obj.hasOwnProperty('condition')) {
  857. if (player_obj.condition.hasOwnProperty('debuff')) {
  858. if (player_obj.condition.debuff.length > 0) {
  859. player_need_clear = true;
  860. }
  861. }
  862. }
  863. } else {
  864. player_stats.need_heal.push(false);
  865. }
  866. player_stats.need_clear.push(player_need_clear);
  867. }
  868. }
  869.  
  870. for (const i in battle.formation) {
  871. if (battle.formation.hasOwnProperty(i)) {
  872. const front_id = parseInt(battle.formation[i]);
  873. if (cid===front_id) {
  874. front_cid = i;
  875. }
  876. player_stats.front_need_heal.push(battle.player.param[front_id].hpmax - battle.player.param[front_id].hp !== 0);
  877. }
  878. }
  879. console.log('front_cid: '+front_cid);
  880. console.log('player_stats: ');
  881. console.log(player_stats);
  882. if (pot_type==='Clarity Herb') {
  883. if (battle.hasOwnProperty('event')) {
  884. let item_obj = Object.values(battle.event.item).find(x => x.name === pot_type);
  885. if (item_obj !== undefined) {
  886. if (item_obj.number > 0 && front_cid !== false && player_stats.front_need_heal[front_cid]) {
  887. do_click_heal = true;
  888. }
  889. }
  890. }
  891. } else if (pot_type==='Green Potion') {
  892. if (battle.hasOwnProperty('temporary')) {
  893. if (battle.temporary.hasOwnProperty('small')) {
  894. let item_obj = parseInt(battle.temporary.small);
  895. console.log('item_obj');
  896. console.log(item_obj);
  897. if (item_obj !== undefined) {
  898. if (item_obj > 0 && front_cid !== false && player_stats.front_need_heal[front_cid]) {
  899. do_click_heal = true;
  900. }
  901. }
  902. }
  903. }
  904. } else if (pot_type==='Blue Potion') {
  905. if (battle.hasOwnProperty('temporary')) {
  906. if (battle.temporary.hasOwnProperty('large')) {
  907. let item_obj = parseInt(battle.temporary.large);
  908. console.log('item_obj');
  909. console.log(item_obj);
  910. if (item_obj !== undefined) {
  911. if (item_obj > 0 && player_stats.front_need_heal.indexOf(true)>=0) {
  912. do_click_heal = true;
  913. }
  914. }
  915. }
  916. }
  917. }
  918. console.log('do_click_heal:');
  919. console.log(do_click_heal);
  920.  
  921. let clickCancel = function() {
  922. clickAndNegCheck(query.battle_ui.heal_pop_up.cancel,0,my_profile+"Clicking cancel from pot pop up",callback);
  923. };
  924.  
  925. let clickUse = function() {
  926. clickAndNegCheck(query.battle_ui.heal_pop_up.use,0,my_profile+"Clicking use from pot pop up",callback);
  927. };
  928. let clickFront = function() {
  929. clickAndCheck(query.battle_ui.char_ico,front_cid,query.battle_ui.summon_panel+":not(.mask-black)",0,my_profile+"Clicking char_ico from pot pop up",callback);
  930. };
  931.  
  932. let clickPot = function() {
  933. console.log(clickPot.name);
  934. let query_qty = ">.txt-having>.having-num";
  935. let pot_available = false;
  936. let init_clickPot = function () {
  937. if (checkExist(query.battle_ui.heal_pop_up[pot_type]+query_qty)) {
  938. if ( parseInt(document.querySelector(query.battle_ui.heal_pop_up[pot_type]+query_qty).innerHTML) > 0 ) {
  939. pot_available = true;
  940. if (pot_type == 'Blue Potion') {
  941. clickAndNegCheck(query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking "+ pot_type +" pot",clickUse);
  942. }else if (pot_type == 'Green Potion') {
  943. clickAndNegCheck(query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking "+ pot_type +" pot",clickFront);
  944. }else if (pot_type == 'Clarity Herb') {
  945. clickAndNegCheck(query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking "+ pot_type +" pot",clickFront);
  946. }else{
  947. console.log("pot_type unknown");
  948. clickCancel();
  949. }
  950. }
  951. // console.log("pot qty not > 0");
  952. // clickCancel();
  953. // }
  954. // }else{
  955. // console.log("element not exist");
  956. // clickCancel();
  957. }
  958. if (!pot_available) {
  959. clickCancel();
  960. }
  961. };
  962. checkEl(query.battle_ui.heal_pop_up[pot_type]+">img",0,init_clickPot);
  963. };
  964. if (do_click_heal) {
  965. clickAndCheck(query.battle_ui.heal,0,query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking heal pop up",clickPot);
  966. } else {
  967. if (typeof callback == "function") {
  968. callback();
  969. }
  970. }
  971.  
  972. }
  973.  
  974. function usePots(pot_type,list_cid=[],callback=false) {
  975. console.log('usePots');
  976. console.log('pot_type');
  977. console.log(pot_type);
  978. console.log('list_cid');
  979. console.log(list_cid);
  980. if (list_cid > 0) {
  981. let new_list_cid = Object.values(list_cid);
  982. new_list_cid.splice(0,1);
  983. let next_clear = function(){usePots(pot_type,new_list_cid, callback);};
  984. usePot(pot_type,parseInt(list_cid[0]),next_clear);
  985. } else {
  986. if (typeof callback == "function") {
  987. callback();
  988. }
  989. }
  990. }
  991.  
  992. // function usePot (pot_type,char_id=false,callback=false) {
  993. // // console.log(usePot.name);
  994. // let is_front_healable = [];
  995. // let is_player_reviveable = [];
  996. // let is_player_healable = [];
  997. // for (const i in battle.player.param) {
  998. // if (battle.player.param.hasOwnProperty(i)) {
  999. // if (battle.player.param[i].alive === 1) {
  1000. // is_player_reviveable.push(false);
  1001. // is_player_healable.push(battle.player.param[i].hpmax - battle.player.param[i].hp !== 0);
  1002. // }else{
  1003. // is_player_reviveable.push(true);
  1004. // is_player_healable.push(false);
  1005. // }
  1006. // }
  1007. // }
  1008. // for (const i in rep.formation) {
  1009. // if (rep.formation.hasOwnProperty(i)) {
  1010. // const alive_id = parseInt(rep.formation[i]);
  1011. // is_front_healable.push(battle.player.param[alive_id].hpmax - battle.player.param[alive_id].hp !== 0);
  1012. // }
  1013. // }
  1014. // let query_qty = ">.txt-having>.having-num";
  1015. // let clickUse = function() {
  1016. // clickAndNegCheck(query.battle_ui.heal_pop_up.use,0,my_profile+"Clicking use from pot pop up",callback);
  1017. // };
  1018. // let clickFront = function() {
  1019. // 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);
  1020. // };
  1021. // let clickCancel = function() {
  1022. // clickAndNegCheck(query.battle_ui.heal_pop_up.cancel,0,my_profile+"Clicking cancel from pot pop up",callback);
  1023. // };
  1024. // let clickPot = function() {
  1025. // console.log(clickPot.name);
  1026. // if (checkExist(query.battle_ui.heal_pop_up[pot_type]+query_qty)) {
  1027. // if ( parseInt(document.querySelector(query.battle_ui.heal_pop_up[pot_type]+query_qty).innerHTML) > 0 ) {
  1028. // if (pot_type == "blue") {
  1029. // clickAndNegCheck(query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking "+ pot_type +" pot",clickUse);
  1030. // }else if (pot_type == "green") {
  1031. // clickAndNegCheck(query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking "+ pot_type +" pot",clickFront);
  1032. // }else{
  1033. // console.log("pot_type unknown");
  1034. // clickCancel();
  1035. // }
  1036. // }else{
  1037. // console.log("pot qty not > 0");
  1038. // clickCancel();
  1039. // }
  1040. // }else{
  1041. // console.log("element not exist");
  1042. // clickCancel();
  1043. // }
  1044. // };
  1045. // let clickHeal = function() {
  1046. // console.log(clickHeal.name);
  1047. // clickAndCheck(query.battle_ui.heal,0,query.battle_ui.heal_pop_up[pot_type]+">img",0,my_profile+"Clicking heal pop up",clickPot,20);
  1048. // };
  1049. // let do_heal = false;
  1050. // if (pot_type=="blue" && is_front_healable.indexOf(true)>=0) {
  1051. // do_heal = true;
  1052. // }else if (pot_type=="green" && is_player_healable[char_id]) {
  1053. // do_heal = true;
  1054. // }else{
  1055. // if (typeof callback == "function") {
  1056. // callback();
  1057. // }
  1058. // }
  1059. // if (do_heal) {
  1060. // checkEl(query.battle_ui.heal,0,clickHeal);
  1061. // }
  1062. // }
  1063.  
  1064. function clickBackup(callback=false) {
  1065. let check_backup = function() {
  1066. let el_btn, backup_msg;
  1067. if (Array.from(document.querySelector(query.battle_ui.backup_pop_up.request).classList).indexOf("disable") >= 0) {
  1068. el_btn = query.battle_ui.backup_pop_up.cancel;
  1069. backup_msg = "cancel";
  1070. } else {
  1071. el_btn = query.battle_ui.backup_pop_up.request;
  1072. backup_msg = "request";
  1073. }
  1074. clickAndNegCheck(el_btn,0,my_profile+"Clicking "+backup_msg,callback,10);
  1075. };
  1076. clickAndCheck(query.battle_ui.button.assist,0,query.battle_ui.backup_pop_up.request,0,my_profile+"Clicking backup",check_backup,10);
  1077. }
  1078.  
  1079. function clickBack(callback=false){
  1080. clickAndCheck(".btn-command-back.display-on",0,"div.prt-member",0,my_profile+"Clicking back",callback,10);
  1081. }
  1082.  
  1083. function clickSummonPanel(callback=false){
  1084. console.log(clickSummonPanel.name);
  1085. let query1 = ".prt-list-top.btn-command-summon.summon-on";
  1086. let query2 = ".prt-summon-list.opened";
  1087. let query3 = ".prt-list-top.btn-command-summon.summon-off";
  1088. let qid1 = 0, qid2 = 0, qid3 = 0;
  1089. let msg = my_profile+"Clicking summon panel";
  1090. let old_top = -1;
  1091. let old_left = -1;
  1092. let loop_clickAndCheck = setInterval(function() {
  1093. console.log(clickAndCheck.name + ", check: " + query2 + "["+(qid2.toString())+"], click: " + query1 + "["+(qid1.toString())+"]");
  1094. if (checkExist(query2,qid2) || checkExist(query3,qid3)) {
  1095. clearInterval(loop_clickAndCheck);
  1096. if (typeof callback == "function") {
  1097. callback();
  1098. }
  1099. }else{
  1100. if (checkExist(query1,qid1)) {
  1101. if (old_top==document.querySelectorAll(query1)[qid1].getBoundingClientRect().top && old_left==document.querySelectorAll(query1)[qid1].getBoundingClientRect().left) {
  1102. clickNow(query1,qid1,msg);
  1103. }else{
  1104. old_top = document.querySelectorAll(query1)[qid1].getBoundingClientRect().top;
  1105. old_left = document.querySelectorAll(query1)[qid1].getBoundingClientRect().left;
  1106. }
  1107. }
  1108. }
  1109. }, 200);
  1110. }
  1111.  
  1112. function clickSummon(summon_id,callback1=false,callback2=false){
  1113. console.log(clickSummon.name);
  1114. summon_id = summon_id-1;
  1115. if (Array.from(document.querySelectorAll(".lis-summon")[summon_id].classList).indexOf("btn-summon-available")>=0){
  1116. let loop_clickSummon = setInterval(function() {
  1117. 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))){
  1118. clearInterval(loop_clickSummon);
  1119. let q_img = '.lis-summon>img';
  1120. let q_skin = '#wrapper > div.contents > div.cnt-raid > div.prt-command > div.prt-command-summon.summon-show > div > div.lis-summon.is-skin.on.btn-summon-available > div.prt-summon-skin > img';
  1121. if (summon_id == 0) {
  1122. if (checkExist(q_skin,0)) {
  1123. q_img = q_skin;
  1124. }
  1125. }
  1126. clickAndCheck(q_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);
  1127. }
  1128. }, 300);
  1129. }else{
  1130. if (typeof callback2 == "function") {
  1131. callback2();
  1132. }
  1133. }
  1134. }
  1135.  
  1136. function clickOkSummon(callback=false){
  1137. console.log(clickOkSummon.name);
  1138. let el_ok = ".pop-usual.pop-summon-detail>div>.btn-usual-ok.btn-summon-use";
  1139. if (document.querySelector(el_ok) !== null){
  1140. clickAndCheck(el_ok,0,"div.prt-member",0,my_profile+"Clicking summon ok",callback);
  1141. }else{
  1142. if (typeof callback == "function") {
  1143. callback();
  1144. }
  1145. }
  1146. }
  1147. function clickOkSummon2(summon_id,callback=false){
  1148. let el_ok = ".pop-usual.pop-summon-detail>div>.btn-usual-ok.btn-summon-use";
  1149. let summon_el = '.lis-summon[pos="'+(summon_id.toString())+'"]';
  1150. if (document.querySelector(el_ok) !== null){
  1151. let loop_clickOkSummon2 = setInterval(function() {
  1152. console.log(clickOkSummon2.name + ", click: " + el_ok + "[0]");
  1153. if (Array.from(document.querySelector(summon_el).classList).indexOf("tmp-mask")>=0 || Array.from(document.querySelector(summon_el).classList).indexOf("btn-summon-unavailable")>=0) {
  1154. clearInterval(loop_clickOkSummon2);
  1155. if (typeof callback == "function") {
  1156. callback();
  1157. }
  1158. }else{
  1159. if (checkExist(el_ok,0)) {
  1160. clickNow(el_ok,0,my_profile+"Clicking summon ok2");
  1161. }
  1162. }
  1163. }, 1000);
  1164. }else{
  1165. if (typeof callback == "function") {
  1166. callback();
  1167. }
  1168. }
  1169. }
  1170.  
  1171. function selectSummon(preferred_summon,is_trial=false){
  1172. reload(20);
  1173.  
  1174. let init_selectSummon = function() {
  1175. console.log(init_selectSummon.name);
  1176. reload(10);
  1177. const attrib_list = [6,0,1,2,3,4,5];
  1178. let query_summon_list = ".btn-supporter.lis-supporter";
  1179. let el_summon_list = document.querySelectorAll(query_summon_list);
  1180. let preferred_summon_id = false;
  1181. let picked_attrib_id = false;
  1182. let picked_summon_id = false;
  1183. let picked_is_friend = false;
  1184. let is_friend;
  1185. let picked_summon_stars = false;
  1186. let picked_summon_level = false;
  1187. let picked_summon_plus = false;
  1188. let msg;
  1189. let cmd = [], summon_list = {};
  1190. 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){
  1191. msg = my_profile+"Verify not appear, summon list length is "+(el_summon_list.length.toString());
  1192. console.log(msg);
  1193.  
  1194. // check if raid is trial
  1195. if (!is_trial){
  1196. console.log("not trial");
  1197. for (let i = 0; i < el_summon_list.length; i++) {
  1198. let match_preferred = false, replace = false;
  1199. let temp_var, summon_detail, summon_name, summon_level, summon_stars, summon_plus;
  1200. temp_var = el_summon_list[i].querySelector(".prt-supporter-summon");
  1201. summon_detail = temp_var.innerHTML.trim();
  1202. temp_var = el_summon_list[i].querySelector(".prt-supporter-summon");
  1203. summon_detail = temp_var.innerHTML.trim();
  1204. summon_name = summon_detail.substring(summon_detail.indexOf("</span>")+8,summon_detail.length);
  1205. summon_level = parseInt(temp_var.children[0].innerHTML.replace("Lvl ",""));
  1206. temp_var = Array.from(el_summon_list[i].querySelector(".prt-summon-skill").classList);
  1207. if (temp_var.indexOf("bless-rank3-style")>=0){
  1208. summon_stars = 5;
  1209. }else if (temp_var.indexOf("bless-rank2-style")>=0){
  1210. summon_stars = 4;
  1211. }else if (temp_var.indexOf("bless-rank1-style")>=0){
  1212. summon_stars = 3;
  1213. }else{
  1214. summon_stars = 0;
  1215. }
  1216. temp_var = el_summon_list[i].querySelector(".prt-summon-quality");
  1217. if (temp_var !== null){
  1218. summon_plus = parseInt(temp_var.innerHTML.replace("+",""));
  1219. }else{
  1220. summon_plus = 0;
  1221. }
  1222. temp_var = false;
  1223. is_friend = Array.from(el_summon_list[i].querySelector(".prt-supporter-name").classList).indexOf("ico-friend")>=0;
  1224.  
  1225. // loop preferred summon list (specified in parameter)
  1226. for (let j = 0; j < preferred_summon.length; j++) {
  1227. if (preferred_summon[j].name==summon_name && preferred_summon[j].star<=summon_stars){
  1228. match_preferred = true;
  1229. temp_var = j;
  1230. }
  1231. }
  1232.  
  1233.  
  1234. if (match_preferred){
  1235. if (picked_attrib_id===false && picked_summon_id===false){
  1236. replace = true;
  1237. }else{
  1238. if (preferred_summon_id>temp_var){
  1239. replace = true;
  1240. }else if(preferred_summon_id==temp_var){
  1241. if (summon_stars>picked_summon_stars){
  1242. replace = true;
  1243. }else if(summon_stars==picked_summon_stars){
  1244. if (!picked_is_friend && is_friend){
  1245. replace = true;
  1246. }else if(picked_is_friend && is_friend){
  1247. if (summon_level>picked_summon_level){
  1248. replace = true;
  1249. }else if(summon_level==picked_summon_level){
  1250. if (summon_plus>picked_summon_plus){
  1251. replace = true;
  1252. }
  1253. }
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. if (replace){
  1260. picked_attrib_id = Array.from(document.querySelectorAll(".prt-supporter-attribute")).indexOf(el_summon_list[i].parentElement);
  1261. picked_summon_id = i;
  1262. preferred_summon_id = temp_var;
  1263. picked_summon_stars = summon_stars;
  1264. picked_is_friend = is_friend;
  1265. picked_summon_level = summon_level;
  1266. picked_summon_plus = summon_plus;
  1267. }
  1268. }
  1269. console.log([picked_attrib_id,picked_summon_id,preferred_summon_id]);
  1270. if (picked_summon_id===false){
  1271. console.log("go to trial");
  1272. cmd.push({"cmd":"log","level":"process","msg":message.summon.not_found});
  1273. xhr.open("POST", server);
  1274. xhr.send(JSON.stringify(cmd));
  1275. gotoHash("trial");
  1276. }else{
  1277. console.log("summon_found");
  1278. let pickSummon = function() {
  1279. scroll_To(query_summon_list,picked_summon_id);
  1280. clickEl(query_summon_list,picked_summon_id,message.summon.select);
  1281. };
  1282. let clickAndCheckSummon = function(callback=false){
  1283. let el_tab_ele_ico = ".prt-type-text";
  1284. let el_summon_container = ".prt-supporter-attribute";
  1285. let loop_clickAndCheckSummon = setInterval(function() {
  1286. console.log(clickAndCheckSummon.name + ", check: " + el_summon_container + "[" + picked_attrib_id + "], click: " + el_tab_ele_ico + "["+(attrib_list[picked_attrib_id].toString())+"]");
  1287. if (Array.from(document.querySelectorAll(el_summon_container)[picked_attrib_id].classList).indexOf("disableView") == -1) {
  1288. clearInterval(loop_clickAndCheckSummon);
  1289. if (typeof callback == "function") {
  1290. callback();
  1291. }
  1292. }else{
  1293. if (checkExist(el_tab_ele_ico, attrib_list[picked_attrib_id])) {
  1294. clickNow(el_tab_ele_ico, attrib_list[picked_attrib_id], message.summon.pick_tab);
  1295. }
  1296. }
  1297. }, 300);
  1298. };
  1299. clickAndCheckSummon(pickSummon);
  1300. }
  1301. }else{
  1302. console.log("is trial");
  1303. query_summon_list = ".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter";
  1304. el_summon_list = document.querySelectorAll(query_summon_list);
  1305. for (let i = 0; i < el_summon_list.length; i++) {
  1306. is_friend = Array.from(el_summon_list[i].querySelector(".prt-supporter-name").classList).indexOf("ico-friend")>=0;
  1307. if (!is_friend){
  1308. if (picked_summon_id===false){
  1309. picked_summon_id = i;
  1310. }
  1311. }
  1312. }
  1313. if (picked_summon_id!==false){
  1314. scroll_To(".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter",picked_summon_id);
  1315. clickEl(".prt-supporter-attribute:not(.disableView)>.btn-supporter.lis-supporter",picked_summon_id,message.summon.select);
  1316. }
  1317. }
  1318. }else{
  1319. msg = my_profile+"Verify might appear, summon list length is "+(el_summon_list.length.toString());
  1320. clearInterval(reload_counter);
  1321. console.log(msg);
  1322. cmd.push({"cmd":"log","level":"process","msg":msg});
  1323. cmd.push({"cmd":"log","level":"notif","msg":msg});
  1324. xhr.open("POST", server);
  1325. xhr.send(JSON.stringify(cmd));
  1326. }
  1327. };
  1328. checkEl(".prt-supporter-title",0,init_selectSummon);
  1329. }
  1330.  
  1331. function doChat(callback=false) {
  1332. console.log(doChat.name);
  1333. let clickDialog = function() {
  1334. console.log(clickDialog.name);
  1335. clickAndNegCheck(query.battle_ui.chat_pop_up.dialog,0,my_profile+"Clicking chat dialog",callback);
  1336. };
  1337. let clickChat = function() {
  1338. console.log(clickChat.name);
  1339. if (checkExist(query.battle_ui.chat+">.ico-attention",0)) {
  1340. clickAndCheck(query.battle_ui.chat,0,query.battle_ui.chat_pop_up.dialog,0,my_profile+"Clicking chat pop up",clickDialog,20);
  1341. }else{
  1342. if (typeof callback == "function") {
  1343. callback();
  1344. }
  1345. }
  1346. };
  1347. checkEl(query.battle_ui.chat,0,clickChat);
  1348. }
  1349.  
  1350. function backFromTrial(){
  1351. let cmd = [];
  1352. cmd.push({"cmd":"log","level":"process","msg":message.raid.trial.end});
  1353. xhr.open("POST", server);
  1354. xhr.send(JSON.stringify(cmd));
  1355. gotoHash("main");
  1356. }
  1357.  
  1358. function gotoResult() {
  1359. console.log(gotoResult.name);
  1360. console.log(is_host);
  1361. if (is_host || window.location.hash.indexOf("#raid/")>=0) {
  1362. gotoHash("quest");
  1363. }else if (window.location.hash.indexOf("#raid_multi")>=0) {
  1364. reloadNow();
  1365. }
  1366. }
  1367.  
  1368. function attack(rep){
  1369. console.log(attack.name);
  1370. let cmd = [];
  1371. let reps = rep.scenario;
  1372. let win = false;
  1373. let is_last_raid = false;
  1374. let ougi = 0;
  1375. let msg = "";
  1376. for (let i = 0; i < reps.length; i++) {
  1377. if (reps[i].cmd =="win"){
  1378. if (reps[i].is_last_raid){is_last_raid=true;}
  1379. win=true;
  1380. }else if (reps[i].cmd=="special" || reps[i].cmd=="special_npc"){
  1381. const char_name = battle.player.param[parseInt(battle.formation[reps[i].pos])].name;
  1382. msg += my_profile+char_name+" used ougi \""+reps[i].name+"\".\n";
  1383. if (reps[i].total){msg += my_profile+char_name+" dealt "+reps[i].total[0].split.join("")+" damage.\n";}
  1384. ougi++;
  1385. }else if (reps[i].cmd=="attack" && reps[i].from=="player"){
  1386. const char_name = battle.player.param[parseInt(battle.formation[reps[i].pos])].name;
  1387. if (reps[i].damage.length==3){
  1388. msg += my_profile+char_name+" made a triple attack.\n";
  1389. }else if (reps[i].damage.length==2){
  1390. msg += my_profile+char_name+" made a double attack.\n";
  1391. }
  1392. msg += my_profile+char_name+ " dealt ";
  1393. for (let ii=0; ii<reps[i].damage.length; ii++){
  1394. msg += reps[i].damage[ii][0].value.toString();
  1395. if (ii<reps[i].damage.length-1){
  1396. msg += ", ";
  1397. }else{
  1398. msg += " damage.\n";
  1399. }
  1400. }
  1401. }
  1402. }
  1403.  
  1404. if(win){
  1405. cmd.push({"cmd":"log","level":"process","msg":msg+my_profile+"Foe defeated."});
  1406. }else{
  1407. cmd.push({"cmd":"log","level":"process","msg":msg+my_profile+"Foe is still alive."});
  1408. cmd.push({"cmd":"press","key":"f5"});
  1409. }
  1410. xhr.open('POST', server);
  1411. xhr.send(JSON.stringify(cmd));
  1412. if(win && is_last_raid){
  1413. gotoResult();
  1414. }else if(win){
  1415. clickEl(".btn-result",0,my_profile+"Go to next round");
  1416. }
  1417. }
  1418.  
  1419. function skillUsed(rep){
  1420. console.log(skillUsed.name);
  1421. let do_reload = false;
  1422. let reps = rep.scenario;
  1423. let win = false, is_last_raid = false;
  1424. console.log(reps);
  1425. for (let i = 0; i < reps.length; i++) {
  1426. const scenario = reps[i];
  1427. if (scenario.cmd =="ability"){
  1428. if (reloadable_skill.indexOf(scenario.name)>= 0) {
  1429. do_reload = true;
  1430. }
  1431. }else if (scenario.cmd =="damage") {
  1432. if (scenario.to == "player") {
  1433. for (let j = 0; j < scenario.list.length; j++) {
  1434. const s = scenario.list[j];
  1435. if (s.hp !== undefined && s.pos !== undefined) {
  1436. battle.player.param[s.pos].hp = s.hp;
  1437. }
  1438. }
  1439. }
  1440. }else if (scenario.cmd =="finished"){
  1441. win=true;
  1442. is_last_raid=true;
  1443. }else if (scenario.cmd == "win"){
  1444. if (scenario.is_last_raid) {
  1445. is_last_raid=true;
  1446. }
  1447. win=true;
  1448. }
  1449. }
  1450. if(win && is_last_raid){
  1451. gotoResult();
  1452. }else if (win && !is_last_raid) {
  1453. clickEl(".btn-result",0,my_profile+"Go to next round");
  1454. }else if(do_reload){
  1455. reloadNow();
  1456. }
  1457. }
  1458.  
  1459. function summonUsed(rep){
  1460. console.log(summonUsed.name);
  1461. let do_reload = false;
  1462. let reps = rep.scenario;
  1463. let win = false,
  1464. is_last_raid = false;
  1465. for (let i = 0; i < reps.length; i++) {
  1466. const scenario = reps[i];
  1467. if (scenario.cmd == "finished"){
  1468. win=true;
  1469. is_last_raid=true;
  1470. }else if (scenario.cmd == "win"){
  1471. if (scenario.is_last_raid){
  1472. is_last_raid=true;
  1473. }
  1474. win=true;
  1475. }
  1476. }
  1477. if (battle.lyria_pos >= 0) {
  1478. do_reload = true;
  1479. }
  1480. if(win && is_last_raid){
  1481. gotoResult();
  1482. }else if(do_reload){
  1483. reloadNow();
  1484. }
  1485. }
  1486.  
  1487. function potUsed(rep) {
  1488. console.log(potUsed.name);
  1489. let reps = rep.scenario;
  1490. for (let i = 0; i < reps.length; i++) {
  1491. const scenario = reps[i];
  1492. if (scenario.cmd == "heal") {
  1493. for (let j = 0; j < scenario.list.length; j++) {
  1494. const s = scenario.list[j];
  1495. if (s.hp !== undefined && s.pos !== undefined) {
  1496. battle.player.param[s.pos].hp = s.hp;
  1497. }
  1498. }
  1499. }
  1500. }
  1501. }
  1502.  
  1503.  
  1504. function clickAttack(callback=false) {
  1505. let hp = ((parseInt(battle.boss.param[0].hp) / parseInt(battle.boss.param[0].hpmax)) * 100).toString();
  1506. if (hp.indexOf(".")>=0){
  1507. hp = hp.substring(0,hp.indexOf("."));
  1508. }
  1509. console.log(hp);
  1510. let attack_msg = my_profile+"Foe hp is "+hp+"% left, commencing attack";
  1511. clickAndCheck(".btn-attack-start.display-on",0,".btn-attack-cancel.btn-cancel.display-on",0,attack_msg,callback,20);
  1512. }
  1513.  
  1514. function charMoveSet(cid,skill_list,callback) {
  1515. if (!(Number.isInteger(cid))) {
  1516. cid = battle.player.param.findIndex(x => x.name === cid);
  1517. }
  1518. console.log(charMoveSet.name + ': ' + cid);
  1519. let char = battle.player.param[cid];
  1520. console.log(char.name);
  1521. if (char !== undefined) {
  1522. let can_use_skill = true;
  1523. if (skill_list.length>0) {
  1524. let new_skill_list = Object.values(skill_list);
  1525. for (let i = 0; i < skill_list.length; i++) {
  1526. const skill = skill_list[i];
  1527. if (document.querySelector(query.battle_ui.skill['char'+(cid+1).toString()]['skill'+(skill.toString())]).attributes.state.value != "2") {
  1528. new_skill_list.splice(new_skill_list.indexOf(skill),1);
  1529. }
  1530. }
  1531. skill_list = new_skill_list;
  1532. if ("debuff" in char.condition) {
  1533. for (let i = 0; i < char.condition.debuff.length; i++) {
  1534. const debuff = char.condition.debuff[i];
  1535. if (debuff.status == "1111" || debuff.status == "1102") {
  1536. can_use_skill = false;
  1537. }
  1538. // 1102
  1539. }
  1540. }
  1541. }
  1542. if (char.alive===1 && skill_list.length>0 && can_use_skill) {
  1543. let click_back = function(){clickBack(callback);};
  1544. let use_skills = function(){useSkills(cid,skill_list,click_back);};
  1545. let click_char = function(){clickChar(cid+1,use_skills);};
  1546. click_char();
  1547. } else {
  1548. if (typeof callback == "function") {
  1549. callback();
  1550. }
  1551. }
  1552. } else {
  1553. if (typeof callback == "function") {
  1554. callback();
  1555. }
  1556. }
  1557. }
  1558.  
  1559.  
  1560. function toggleOugi(ougi, callback=false) {
  1561. let init_toggleOugi = function() {
  1562. let current_ougi = "."+document.querySelector(query.battle_ui.ougi).classList[1];
  1563. if (query.battle_ui.toggle_ougi[ougi] != current_ougi){
  1564. 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);
  1565. }else{
  1566. if (typeof callback == "function") {
  1567. callback();
  1568. }
  1569. }
  1570. };
  1571. checkEl(query.battle_ui.ougi,0,init_toggleOugi);
  1572. }
  1573.  
  1574. function summoning(summon_id,callback=false) {
  1575. console.log(summoning.name);
  1576. let summon_cd;
  1577. console.log('test 1');
  1578. if (summon_id === 5) {
  1579. console.log('test 2');
  1580. summon_cd = battle.supporter.recast;
  1581. console.log('test 3');
  1582. } else if (battle.summon[summon_id] !== undefined) {
  1583. console.log('test 4');
  1584. summon_cd = battle.summon[summon_id].recast;
  1585. console.log('test 5');
  1586. }
  1587. console.log('test 6');
  1588. if (summon_cd === "0") {
  1589. console.log('test 7');
  1590. let summon_ok = function(){clickOkSummon(callback);};
  1591. let summon = function(){clickSummon(summon_id+1,summon_ok,callback);};
  1592. let summon_p = function(){clickSummonPanel(summon);};
  1593. summon_p();
  1594. } else {
  1595. console.log('test 8');
  1596. if (typeof callback == "function") {
  1597. callback();
  1598. }
  1599. }
  1600. }
  1601.  
  1602. function pickUnclaimedRaid(rep) {
  1603. if (rep.count > 0) {
  1604. let el_raid = ".prt-raid-info";
  1605. let init_pickUnlaimedRaid = function() {
  1606. gotoHash(rep.list[0].href);
  1607. };
  1608. checkEl(el_raid,0,init_pickUnlaimedRaid);
  1609. }else{
  1610. gotoHash('main');
  1611. }
  1612. }
  1613.  
  1614. let battleLogic = function(case_battle) {
  1615. console.log(battleLogic.name);
  1616. console.log('case_battle:');
  1617. console.log(case_battle);
  1618. clearInterval(reload_counter);
  1619. };
  1620.  
  1621. function startRaid(rep){
  1622. reload(15);
  1623. battle = rep;
  1624. is_host = rep.is_host;
  1625. for (let i = 0; i < battle.player.param.length; i++) {
  1626. const c = battle.player.param[i];
  1627. if (c.alive === 1) {
  1628. is_wiped = false;
  1629. }
  1630. }
  1631.  
  1632. let check_exist = setInterval(function() {
  1633. console.log("querying enemy name to appear");
  1634. 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){
  1635. console.log("check width enemy name");
  1636. 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){
  1637. console.log("found enemy name");
  1638. clearInterval(check_exist);
  1639. let is_quest_id_valid = false;
  1640. let is_twitter_valid = false;
  1641. try{
  1642. console.log(rep.quest_id);
  1643. if (rep.quest_id!==undefined) {
  1644. is_quest_id_valid = true;
  1645. }
  1646. }
  1647. catch(err){
  1648. console.log(err.message);
  1649. }
  1650. console.log("is_quest_id_valid:" +(is_quest_id_valid).toString());
  1651. try{
  1652. console.log(rep.twitter.monster);
  1653. if (rep.twitter.monster!==undefined) {
  1654. is_twitter_valid = true;
  1655. }
  1656. }
  1657. catch(err){
  1658. console.log(err.message);
  1659. }
  1660. console.log("is_twitter_valid:" +(is_twitter_valid).toString());
  1661. let case_battle = false;
  1662. if (is_quest_id_valid){
  1663. if (battle.is_trialbattle) {
  1664. case_battle = 99;
  1665. }else{
  1666. for (let i in quests_id) {
  1667. if (rep.quest_id == quests_id[i] && case_battle === false) {
  1668. case_battle = parseInt(i)+1;
  1669. }
  1670. }
  1671. }
  1672. }
  1673. if (case_battle === false && is_twitter_valid){
  1674. for (let i in monsters_name) {
  1675. if (rep.twitter.monster==monsters_name[i] && case_battle === false) {
  1676. case_battle = parseInt(i)+1;
  1677. }
  1678. }
  1679. }
  1680. console.log("case_battle:" + case_battle.toString());
  1681. let hp = ((parseInt(rep.boss.param[0].hp) / parseInt(rep.boss.param[0].hpmax)) * 100).toString();
  1682. if (hp.indexOf(".")>=0){
  1683. hp = hp.substring(0,hp.indexOf("."));
  1684. }
  1685. battleLogic(case_battle);
  1686. }
  1687. }
  1688. }, 300);
  1689. }
  1690.  
  1691. function clickChar(param,callback=false) {
  1692. 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);
  1693. }
  1694.  
  1695. function clickBoss(boss_id,callback=false) {
  1696. const boss_id_str = (boss_id+1).toString();
  1697. if (battle.boss.param[boss_id] !== undefined || battle.boss.param[boss_id].alive === 1) {
  1698. clickAndCheck('.enemy-info>.name',boss_id,'.btn-targeting.enemy-'+boss_id_str+'.lock-on',0,my_profile+'Clicking Boss '+boss_id_str,callback);
  1699. } else {
  1700. if (typeof callback == "function") {
  1701. callback();
  1702. }
  1703. }
  1704. }
  1705.  
  1706. function raidFinish(rep,send_all_loot=false){
  1707. console.log(raidFinish.name);
  1708. reload(10);
  1709. let cmd = [];
  1710. let tracked_loot = [];
  1711. let check_timer = true;
  1712. cmd.push({"cmd":"log","level":"process","msg":message.raid.finish});
  1713.  
  1714. let all_loot = {};
  1715. let important_loot = {};
  1716. for (const i in rep.rewards.reward_list) {
  1717. if (rep.rewards.reward_list.hasOwnProperty(i)) {
  1718. const loots = rep.rewards.reward_list[i];
  1719. for (const j in loots) {
  1720. if (loots.hasOwnProperty(j)) {
  1721. const loot = loots[j];
  1722. if ( ( ['weapon','summon'].indexOf(loot.type) >= 0 ) && loot.rarity=='4') {
  1723. if (tracked_loot.indexOf(loot.name)===-1) {
  1724. tracked_loot.push(loot.name);
  1725. }
  1726. } else if (tracker_reward_weapons.indexOf(loot.name) >= 0 || tracker_reward_summons.indexOf(loot.name) >= 0 || tracker_reward_items.indexOf(loot.name) >= 0) {
  1727. if (tracked_loot.indexOf(loot.name)===-1) {
  1728. tracked_loot.push(loot.name);
  1729. }
  1730. }
  1731. if (all_loot[loot.name]===undefined) {
  1732. all_loot[loot.name] = parseInt(loot.count);
  1733. } else {
  1734. all_loot[loot.name] += parseInt(loot.count);
  1735. }
  1736. }
  1737. }
  1738. }
  1739. }
  1740. if (send_all_loot) {
  1741. important_loot = all_loot;
  1742. } else {
  1743. for (const loot in all_loot) {
  1744. if (all_loot.hasOwnProperty(loot)) {
  1745. const qty = all_loot[loot];
  1746. if (tracked_loot.indexOf(loot)>=0) {
  1747. important_loot[loot] = qty;
  1748. }
  1749. }
  1750. }
  1751. }
  1752. console.log(important_loot);
  1753. if (Object.keys(important_loot).length > 0) {
  1754. cmd.push({"cmd":"reward","payload":important_loot});
  1755. cmd.push({"cmd":"log","level":"summary","msg":Object.keys(important_loot).length});
  1756. }
  1757.  
  1758. if (tracked_item !== false){
  1759. let data_track = my_profile+"Current Status:";
  1760. let temp_str;
  1761. for (let item in tracked_item){
  1762. if (tracked_item.hasOwnProperty(item)) {
  1763. let item_qty = parseInt(tracked_item[item].number);
  1764. let drop_qty = 0;
  1765. if (all_loot[tracked_item[item].name] !== undefined) {
  1766. drop_qty = all_loot[tracked_item[item].name];
  1767. }
  1768. temp_str = "\n- "+tracked_item[item].name+": "+(item_qty + drop_qty).toString();
  1769. if (all_loot[tracked_item[item].name] !== undefined) {
  1770. temp_str += ' ( +'+(drop_qty).toString()+' )';
  1771. }
  1772. data_track += temp_str;
  1773. }
  1774. }
  1775. cmd.push({"cmd":"log","level":"summary","msg":data_track,"split":0});
  1776. }
  1777. if (check_timer){
  1778. cmd.push({"cmd":"check_timer"});
  1779. }
  1780. xhr.open('POST', server);
  1781. xhr.send(JSON.stringify(cmd));
  1782. let gotoMain = function() {gotoHash("main");};
  1783. checkEl(".mask",0,gotoMain);
  1784. }
  1785.  
  1786. function quitTrial(){
  1787. let doit3 = function(){clickEl(".btn-usual-ok",0,message.raid.trial.ok);};
  1788. let doit2 = function(){clickEl(".btn-withdrow.btn-red-m",0,message.raid.trial.retreat,doit3);};
  1789. let doit1 = function(){clickEl(".btn-raid-menu.menu",0,message.raid.trial.open_menu,doit2);};
  1790. clickAndNegCheck(query.battle_ui.trial_pop_up.close,0,message.raid.trial.close_pop_up,doit1);
  1791. }
  1792.  
  1793. function missionComplete(cmd=[]) {
  1794. clearInterval(reload_counter);
  1795. // let cmd = [];
  1796. cmd.push({"cmd":"log","level":"notif","msg":my_profile+"Objective cleared. Mission complete. "+discord_mention});
  1797. cmd.push({"cmd":"log","level":"summary","msg":my_profile+"Objective cleared. Mission complete."});
  1798. cmd.push({"cmd":"hotkey","keys":["ctrl","w"]});
  1799. xhr.open('POST', server);
  1800. xhr.send(JSON.stringify(cmd));
  1801. }
  1802.  
  1803. let listenNetwork = function() {
  1804. console.log('listenNetwork');
  1805. clearInterval(reload_counter);
  1806. };
  1807.  
  1808. function init() {
  1809. "use strict";
  1810. console.log(init.name);
  1811. reload(5);
  1812. setDebug();
  1813. listenNetwork();
  1814. let checkBody = setInterval(function() {
  1815. console.log(checkBody.name);
  1816. if(document.body !== null){
  1817. clearInterval(checkBody);
  1818. if(document.body.children[0].tagName == "DIV"){
  1819. // reload(30);
  1820. checkError();
  1821. }else{
  1822. console.log("DOM Error");
  1823. reloadNow();
  1824. }
  1825. }
  1826. }, 300);
  1827. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址