NEET Lib

NEET Bot Library

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

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

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