Greasy Fork 还支持 简体中文。

NEET Lib

NEET Bot Library

目前為 2020-02-23 提交的版本,檢視 最新版本

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

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