NEET Lib

NEET Bot Library

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

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