Greasy Fork 支持简体中文。

Idlescape - Snippet

collections of snippets

  1. // ==UserScript==
  2. // @name Idlescape - Snippet
  3. // @namespace test
  4. // @version 0.12
  5. // @description collections of snippets
  6. // @author snefrukai
  7. // @match *://*.idlescape.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=idlescape.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. ;(function () {
  14. ;('use strict')
  15.  
  16. // ========================================================================== //
  17. // * setDefaultPage
  18. // ========================================================================== //
  19.  
  20. // Default Page on Load
  21. // openDefaultPage(setDefaultPage[0]) // ! test
  22.  
  23. var setDefaultPage = [
  24. // ! change and comment out the default page
  25. 'active skill',
  26. // 'Fighting',
  27. // 'Mining',
  28. // 'Foraging',
  29. // 'Fishing',
  30. // 'Smithing',
  31. // 'Farming',
  32. // 'Cooking',
  33. // 'Crafting',
  34. // 'Runecrafting',
  35. // 'Enchanting',
  36. ]
  37.  
  38. function openDefaultPage(setDefaultPage = 'active skill') {
  39. var leftNav = document.getElementsByClassName('drawer-item-left')
  40. // console.log(leftNav)
  41.  
  42. var idlingPage = 'Attack' // set idling page (no action)
  43. var defaultPage = ''
  44.  
  45. // get default page from setting
  46. if (setDefaultPage != 'active skill') defaultPage = setDefaultPage
  47. else {
  48. // get action
  49. var foo = document.getElementsByClassName('status-action')[0].innerText
  50. var getAction = foo.match(/[A-z]+/)[0]
  51. if (getAction == 'Fighting') defaultPage = 'Attack'
  52. else if (getAction == 'Idling') defaultPage = idlingPage
  53. else defaultPage = getAction
  54. }
  55.  
  56. // check default page w left nav. if hit, click
  57. for (let i = 0; i < leftNav.length; i++) {
  58. let sample = leftNav[i].textContent
  59. // console.log(sample)
  60. if (sample == defaultPage) {
  61. leftNav[i].click()
  62. console.log('default page loaded:', defaultPage)
  63. }
  64. }
  65. }
  66.  
  67. // ========================================================================== //
  68. // * shortcuts
  69. // ========================================================================== //
  70.  
  71. // shortcuts() // ! test}
  72.  
  73. function shortcuts(params) {
  74. // ========================================================================== //
  75. // close popups
  76.  
  77. var popupSelector = '.MuiDialog-container'
  78.  
  79. // when press 'Esc'
  80. document.onkeydown = function (e) {
  81. var closePopup = e.key === 'Escape' || e.key === 'Esc'
  82. if (closePopup) if (checkExist(popupSelector)) clickClose()
  83. }
  84.  
  85. // when click outside of popup box
  86. document.querySelector('#root').onclick = function (e) {
  87. // only when popup is shown, only add click to popup
  88. if (checkExist(popupSelector)) {
  89. var popup = document.querySelectorAll(popupSelector)[0]
  90. popup.onclick = function (e) {
  91. // document.querySelector('#root').onclick = function (e) {
  92. var isClosest = e.target.closest('.MuiPaper-root') // popupBox
  93. if (!isClosest) clickClose()
  94. }
  95. }
  96. }
  97.  
  98. function checkExist(selector) {
  99. var tar = document.querySelectorAll(selector)
  100. var isExist = tar.length !== 0
  101. // if (isExist) console.log(selector, 'exist') // ! test
  102. return isExist
  103. }
  104.  
  105. function clickClose() {
  106. foo = '.close-dialog-button'
  107. if (checkExist(foo)) {
  108. document.querySelectorAll(foo)[0].click()
  109. }
  110. }
  111. }
  112.  
  113. // * upgrade selected item by item ID at set interval
  114. // window.upgradeItem_repeat = function (itemID, fn, count, minute) {
  115. // function upgradedItemID(itemID) {
  116. // return items[itemID].trimmedItemID
  117. // }
  118.  
  119. // // function upgrade(itemID, qty) {
  120. // // confirmUpgradeItem(itemID, upgradedItemID(itemID), qty)
  121. // // }
  122.  
  123. // // ! func name 'upgradeItemAll' could cause freeze in tampermonkley
  124. // function upgradeAll(itemID) {
  125. // for (let k = 0; k < itemID.length; k++) {
  126. // confirmUpgradeItemAll(itemID[k], upgradedItemID(itemID[k]))
  127. // console.log('upgrading item ID', itemID[k])
  128. // }
  129. // }
  130.  
  131. // function repeat(itemID, fn = upgradeAll, count = 10000, minute = 5) {
  132. // let i = 0
  133. // function recur() {
  134. // fn(itemID)
  135. // i += 1
  136. // console.log('upgraded', i, 'times')
  137. // setTimeout(function () {
  138. // if (i < count) {
  139. // recur()
  140. // }
  141. // }, 1000 * 60 * minute)
  142. // }
  143. // recur()
  144. // }
  145.  
  146. // repeat(
  147. // (itemID = [
  148. // 768, // air shard
  149. // 769, // water ...
  150. // 770, // earth ...
  151. // 771, // fire ...
  152. // // 890, // mys stone
  153. // // 886, // mys stone charge
  154. // ])
  155. // )
  156. // }
  157.  
  158. // * hide no gathering account's skills
  159. window.checkNoGathering = function () {
  160. var noGatheringSkills = [
  161. 0, // woodcutting
  162. 1, // mining
  163. 2, // firemaking
  164. 4, // fishing
  165. 10, // thiving
  166. 20, // agility
  167. 22, // astrology
  168. ]
  169.  
  170. if (username && username.includes('NG')) {
  171. console.log('Detected "No Gathering".')
  172.  
  173. noGatheringSkills.forEach((skill) => {
  174. $('#nav-skill-tooltip-' + skill.toString()).remove()
  175.  
  176. // in-game func
  177. if (skillsUnlocked[skill] != false) {
  178. skillsUnlocked[skill] = false
  179. forceStopSkill(skill)
  180. if (
  181. PAGES[currentPage].skillID !== undefined &&
  182. PAGES[currentPage].skillID === skill
  183. )
  184. changePage(Pages.Bank)
  185. if (defaultPageOnLoad === skill)
  186. changeSetting(2, Pages.Bank, false, false)
  187. updateSkillWindow(skill) // update ui
  188. updateSkillLevelCap()
  189. }
  190. })
  191.  
  192. console.log('"No Gathering" skills locked and hidden.')
  193. }
  194. }
  195.  
  196. // * eat to full hp
  197. window.autoEatToFull_repeat = function (sec = 1) {
  198. let hp = {
  199. current: 0,
  200. max: 1,
  201. food: 0,
  202. }
  203. let hpSelector = {
  204. current: '#combat-player-hitpoints-current',
  205. max: '#combat-player-hitpoints-max',
  206. }
  207. var activeFoodSelector = '#combat-food-container .text-combat-smoke'
  208.  
  209. function autoEatToFull(params) {
  210. var hpSelectorArr = Object.entries(hpSelector)
  211. for (let i = 0; i < hpSelectorArr.length; i++) {
  212. let str = $(hpSelectorArr[i][1])[0].textContent
  213. hp[hpSelectorArr[i][0]] = getInt(str)
  214. // console.log(str)
  215. }
  216.  
  217. var foodSrc = $(activeFoodSelector)[0].childNodes[1]['src']
  218. var foodName = foodSrc.match(/\w+\.\w+$/g)[0] // match return array
  219. hp['food'] = getInt($(activeFoodSelector)[0].childNodes[2].textContent)
  220. // console.log(foodName)
  221.  
  222. var hpLoss = hp['max'] - hp['current']
  223. var eatFoodAmount = Math.floor(hpLoss / hp['food'])
  224. if (hpLoss > 0) {
  225. for (let i = 0; i < eatFoodAmount; i++) {
  226. $('#combat-footer-minibar-eat-btn').click()
  227. }
  228. console.log('hp loss:', hpLoss, ', ate *', eatFoodAmount, foodName)
  229. } else {
  230. console.log('hp full')
  231. }
  232. }
  233.  
  234. function getInt(str) {
  235. var numb = Number(str.replace(/\D+/g, ''))
  236. return numb
  237. }
  238.  
  239. function repeat(fn = autoEatToFull, count = 60 * 24, sec = 10) {
  240. let i = 0
  241. function recur() {
  242. fn()
  243. i += 1
  244. console.log('auto eat', i, 'times, next check in', sec, 'sec')
  245. setTimeout(function () {
  246. if (i < count) {
  247. recur()
  248. }
  249. }, 1000 * sec)
  250. }
  251. recur()
  252. }
  253. repeat(autoEatToFull, (count = (3600 / sec) * 24 * 10), (sec = sec))
  254. }
  255.  
  256. // * add mastery pool xp to skill after overnight
  257. window.addPoolXPForCount = function (skillID, count, sec = 30) {
  258. var i = 0
  259. var checkPool = setInterval(() => {
  260. checkPoint = parseFloat(
  261. document.querySelector('.mastery-pool-xp-progress-15').textContent
  262. )
  263. // if (checkPoint < 95.5) {
  264. addMasteryXPToPool(skillID, 4046897, false, true)
  265. i = i + 1
  266. console.log('add pool xp:', Skills[skillID], i, 'times')
  267. if (i == count) {
  268. clearInterval(checkPool)
  269. console.log('add pool xp: finished')
  270. }
  271. // }
  272. }, 1000 * sec)
  273. }
  274.  
  275. // * get current gears
  276. // getCurrentGears(3) // ! test
  277. window.getCurrentGears = function (iSet = player.selectedEquipmentSet) {
  278. // function getCurrentGears(iSet = player.selectedEquipmentSet) {
  279. var arr = []
  280. player.equipmentSets[iSet].slotArray.forEach((e) => {
  281. const s = ActiveSkills[game.activeSkill].toLowerCase()
  282. activeSkillNew = s[0].toUpperCase() + s.slice(1)
  283. const itemID = e.item.id
  284. const item = Items[itemID]
  285. const nonCombatUniversal = [
  286. 'Crown_of_Rhaelyx',
  287. 'Clue_Chasers_Insignia',
  288. 'Aorpheats_Signet_Ring',
  289. 'Ring_Of_Wealth',
  290. 'Max_Skillcape',
  291. 'Ancient_Ring_Of_Mastery', // passive
  292. ].includes(item)
  293.  
  294. // console.log(itemID, item, nonCombatUniversal)
  295. if (itemID != -1 && !nonCombatUniversal) {
  296. arr.push(Items[itemID])
  297. }
  298. })
  299. console.log(`${activeSkillNew}\ncurrentGears:`, arr)
  300. }
  301.  
  302. // ========================================================================== //
  303. // * folked from Action Queue
  304. window.actionQueue = function (params) {
  305. // setAction('Build Agility Obstacle', 1, 'Cargo Net')()
  306. window.setAction = function (
  307. actionCategory,
  308. actionName,
  309. skillItem,
  310. skillItem2,
  311. qty
  312. ) {
  313. qty = parseInt(qty, 10)
  314. const itemID = items.findIndex((a) => a.name == actionName)
  315. switch (actionCategory) {
  316. case 'Start Skill':
  317. return setSkillAction(actionName, skillItem, skillItem2)
  318. case 'Start Combat': {
  319. //slayer task selection
  320. if (actionName == 'Slayer Task') {
  321. return () => {
  322. if (combatManager.slayerTask.killsLeft > 0) {
  323. const mID = combatManager.slayerTask.monster.id
  324. const areaData = [
  325. ...areaMenus.combat.areas,
  326. ...areaMenus.slayer.areas,
  327. ].find((a) => a.monsters.includes(mID))
  328. if (
  329. combatManager.isInCombat &&
  330. combatManager.selectedMonster == mID
  331. )
  332. return true
  333. combatManager.stopCombat()
  334. combatManager.selectMonster(mID, areaData)
  335. return true
  336. }
  337. return false
  338. }
  339. }
  340. //dungeon selection
  341. const dungeonIndex = DUNGEONS.findIndex((a) => a.name == actionName)
  342. if (dungeonIndex >= 0) {
  343. return () => {
  344. if (
  345. DUNGEONS[dungeonIndex].requiresCompletion === undefined ||
  346. dungeonCompleteCount[DUNGEONS[dungeonIndex].requiresCompletion] >=
  347. 1
  348. ) {
  349. combatManager.selectDungeon(dungeonIndex)
  350. return true
  351. }
  352. return false
  353. }
  354. }
  355. //regular monster selection
  356. const monsterIndex = MONSTERS.findIndex((a) => a.name == actionName)
  357. const areaData = [
  358. ...areaMenus.combat.areas,
  359. ...areaMenus.slayer.areas,
  360. ].find((a) => a.monsters.includes(monsterIndex))
  361. return () => {
  362. if (checkRequirements(areaData.entryRequirements)) {
  363. if (
  364. !(
  365. combatManager.isInCombat &&
  366. combatManager.selectedMonster == monsterIndex
  367. )
  368. )
  369. combatManager.selectMonster(monsterIndex, areaData)
  370. return true
  371. }
  372. return false
  373. }
  374. }
  375. case 'Change Attack Style': {
  376. if (actionName == 'Select Spell') {
  377. switch (skillItem) {
  378. case 'Normal':
  379. return () => {
  380. const spellID = SPELLS.findIndex((a) => a.name == skillItem2)
  381. //check level req
  382. if (
  383. skillLevel[CONSTANTS.skill.Magic] <
  384. SPELLS[spellID].magicLevelRequired
  385. )
  386. return false
  387. player.toggleSpell(spellID)
  388. return true
  389. }
  390. case 'Curse':
  391. return () => {
  392. const spellID = CURSES.findIndex((a) => a.name == skillItem2)
  393. //check level req
  394. if (
  395. skillLevel[CONSTANTS.skill.Magic] <
  396. CURSES[spellID].magicLevelRequired
  397. )
  398. return false
  399. player.toggleCurse(spellID)
  400. return true
  401. }
  402. case 'Aurora':
  403. return () => {
  404. const spellID = AURORAS.findIndex((a) => a.name == skillItem2)
  405. //check level req
  406. if (
  407. skillLevel[CONSTANTS.skill.Magic] <
  408. AURORAS[spellID].magicLevelRequired
  409. )
  410. return false
  411. //check item req
  412. if (
  413. AURORAS[spellID].requiredItem >= 0 &&
  414. !player.equipment.slotArray
  415. .map((a) => a.item.id)
  416. .includes(AURORAS[spellID].requiredItem)
  417. )
  418. return false
  419. player.toggleAurora(spellID)
  420. return true
  421. }
  422. case 'Ancient':
  423. return () => {
  424. const spellID = ANCIENT.findIndex((a) => a.name == skillItem2)
  425. //check level req
  426. if (
  427. skillLevel[CONSTANTS.skill.Magic] <
  428. ANCIENT[spellID].magicLevelRequired
  429. )
  430. return false
  431. //check dungeon req
  432. if (
  433. dungeonCompleteCount[
  434. ANCIENT[spellID].requiredDungeonCompletion[0]
  435. ] < ANCIENT[spellID].requiredDungeonCompletion[1]
  436. )
  437. return false
  438. player.toggleSpellAncient(spellID)
  439. return true
  440. }
  441. }
  442. }
  443. const style = CONSTANTS.attackStyle[actionName]
  444. return () => {
  445. if (player.attackType == 'magic') {
  446. if (style < 6) return false
  447. } else if (player.attackType === 'ranged') {
  448. if (style > 5 || style < 3) return false
  449. } else {
  450. if (style > 2) return false
  451. }
  452. player.setAttackStyle(player.attackType, actionName)
  453. return true
  454. }
  455. }
  456. case 'Switch Equipment Set': {
  457. const equipSet = parseInt(actionName) - 1
  458. return () => {
  459. if (player.equipmentSets.length > equipSet) {
  460. player.changeEquipmentSet(equipSet)
  461. return true
  462. }
  463. return false
  464. }
  465. }
  466. case 'Equip Item':
  467. return () => {
  468. const bankID = getBankId(itemID)
  469. if (bankID === -1) return false
  470. if (sellItemMode) toggleSellItemMode()
  471. if (items[itemID].canEat) {
  472. selectBankItem(itemID)
  473. equipFoodQty = bank[bankID].qty
  474. equipFood()
  475. return getBankQty(itemID) == 0 //returns false if there is any of the item left in bank (couldn't equip)
  476. }
  477. if (items[itemID].type == 'Familiar') {
  478. let slot = player.equipment.slotArray
  479. .slice(-3)
  480. .findIndex((a) => a.item.id == itemID)
  481. if (slot >= 0) {
  482. player.equipItem(
  483. itemID,
  484. player.selectedEquipmentSet,
  485. `Summon${slot}`,
  486. bank[bankID].qty
  487. )
  488. } else if (player.equipment.slotArray[12].quantity == 0) {
  489. player.equipItem(
  490. itemID,
  491. player.selectedEquipmentSet,
  492. 'Summon1',
  493. bank[bankID].qty
  494. )
  495. } else if (player.equipment.slotArray[13].quantity == 0) {
  496. player.equipItem(
  497. itemID,
  498. player.selectedEquipmentSet,
  499. 'Summon2',
  500. bank[bankID].qty
  501. )
  502. }
  503. return getBankQty(itemID) == 0
  504. }
  505. if (items[itemID].validSlots[0] == 'Quiver') {
  506. player.equipItem(
  507. itemID,
  508. player.selectedEquipmentSet,
  509. 'Quiver',
  510. bank[bankID].qty
  511. )
  512. return getBankQty(itemID) == 0 //returns false if there is any of the item left in bank (couldn't equip)
  513. }
  514. player.equipItem(itemID, player.selectedEquipmentSet)
  515. return (
  516. player.equipment.slots[items[itemID].validSlots[0]].item.id ===
  517. itemID
  518. ) //returns false if the item is not equipped
  519. }
  520. case 'Equip Passive':
  521. return () => {
  522. if (dungeonCompleteCount[15] < 1 || getBankId(itemID) === -1)
  523. return false
  524. player.equipCallback(itemID, 'Passive')
  525. return player.equipment.slots.Passive.item.id === itemID
  526. }
  527. case 'Unequip Item': {
  528. return () => {
  529. for (const i in player.equipment.slots) {
  530. if (player.equipment.slots[i].item.id == itemID) {
  531. player.unequipCallback(i)()
  532. return getBankQty(itemID) > 0 //returns false if there is 0 of the items in bank (no space to unequip)
  533. }
  534. }
  535. return false
  536. }
  537. }
  538. case 'Buy Item':
  539. return () => {
  540. return shop[actionName].buy(qty)
  541. }
  542. case 'Sell Item':
  543. return () => {
  544. if (!bank.find((a) => a.id == itemID)) return false
  545. if (sellItemMode) toggleSellItemMode()
  546. selectBankItem(itemID)
  547. sellItem()
  548. if (showSaleNotifications) swal.clickConfirm()
  549. return true
  550. }
  551. case 'Use Potion':
  552. return () => {
  553. if (!bank.find((a) => a.id == itemID)) return false
  554. usePotion(itemID)
  555. return true
  556. }
  557. case 'Activate Prayers': {
  558. let choice = []
  559. if (actionName != 'None') {
  560. choice.push(PRAYER.findIndex((a) => a.name == actionName))
  561. if (skillItem != 'None') {
  562. choice.push(PRAYER.findIndex((a) => a.name == skillItem))
  563. }
  564. }
  565. return () => {
  566. const validPrayers = choice.filter(
  567. (a) => skillLevel[CONSTANTS.skill.Prayer] > PRAYER[a].prayerLevel
  568. )
  569. changePrayers(validPrayers)
  570. return true
  571. }
  572. }
  573. case 'Build Agility Obstacle': {
  574. const obstacleID = Agility.obstacles.findIndex(
  575. (a) => a.name == skillItem
  576. )
  577. const obstacleNumber = parseInt(actionName) - 1
  578. return () => {
  579. if (chosenAgilityObstacles[obstacleNumber] == obstacleID) return true
  580. if (
  581. !canIAffordThis(
  582. Agility.obstacles[obstacleID].cost,
  583. Agility.obstacles[obstacleID].skillRequirements,
  584. obstacleID
  585. )
  586. )
  587. return false
  588. if (chosenAgilityObstacles[obstacleNumber] >= 0)
  589. destroyAgilityObstacle(obstacleNumber, true)
  590. buildAgilityObstacle(obstacleID, true)
  591. return true
  592. }
  593. }
  594. case 'Remove Agility Obstacle': {
  595. const obstacleNumber = parseInt(actionName) - 1
  596. return () => {
  597. if (chosenAgilityObstacles[obstacleNumber] >= 0)
  598. destroyAgilityObstacle(obstacleNumber, true)
  599. return true
  600. }
  601. }
  602. }
  603. }
  604. }
  605. // * start skill
  606. // call
  607. // start: setAction(actionCategory, actionName, skillItem, skillItem2, qty)
  608. // result = action.start()
  609.  
  610. window.setSkillAction = function (actionName, skillItem1, skillItem2) {
  611. const itemID = items.findIndex((a) => a.name == skillItem1)
  612. let actionID = 0
  613. switch (actionName) {
  614. case 'Agility':
  615. return () => {
  616. if (game.activeSkill !== globalThis.ActiveSkills.Agility)
  617. game.agility.start()
  618. return true
  619. }
  620. case 'Astrology': {
  621. const constellation = Astrology.constellations.find(
  622. (a) => a.name == skillItem1
  623. ) // Find constellation
  624. return () => {
  625. if (skillLevel[CONSTANTS.skill.Astrology] < constellation.level)
  626. return false
  627. if (
  628. game.astrology.activeConstellation.id != constellation.id ||
  629. game.activeSkill != globalThis.ActiveSkills.ASTROLOGY
  630. )
  631. game.astrology.studyConstellationOnClick(constellation)
  632. return true
  633. }
  634. }
  635. case 'Cooking': {
  636. const itemID = items.findIndex((a) => a.name == skillItem2)
  637. const recipe = Cooking.recipes.find((a) => a.itemID == itemID)
  638. const category = recipe.category
  639. if (skillItem1 == 'Active') {
  640. return () => {
  641. const passives = []
  642. ;[0, 1, 2].forEach((c) => {
  643. game.cooking.onCollectStockpileClick(c)
  644. if (c != category && game.cooking.passiveCookTimers.has(c))
  645. passives.push(c)
  646. })
  647. if (skillLevel[CONSTANTS.skill.Cooking] < recipe.cookingLevel)
  648. return false
  649. if (game.cooking.selectedRecipes.get(category).itemID != itemID)
  650. game.cooking.onRecipeSelectionClick(recipe)
  651. if (
  652. game.activeSkill == globalThis.ActiveSkills.COOKING &&
  653. game.cooking.activeCookingCategory == category
  654. )
  655. return true
  656. game.cooking.onActiveCookButtonClick(category)
  657. passives.forEach((a) => game.cooking.onPassiveCookButtonClick(a))
  658. return true
  659. }
  660. } else {
  661. return () => {
  662. ;[0, 1, 2].forEach((category) =>
  663. game.cooking.onCollectStockpileClick(category)
  664. )
  665. if (
  666. skillLevel[CONSTANTS.skill.Cooking] <
  667. Cooking.recipes.find((a) => a.itemID == itemID).level
  668. )
  669. return false
  670. if (game.cooking.selectedRecipes.get(category).itemID != itemID)
  671. game.cooking.onRecipeSelectionClick(recipe)
  672. if (game.cooking.passiveCookTimers.has(category)) return true
  673. game.cooking.onPassiveCookButtonClick(category)
  674. return true
  675. }
  676. }
  677. }
  678. case 'Crafting':
  679. actionID = Crafting.recipes.find((a) => a.itemID == itemID).masteryID
  680. return () => {
  681. if (
  682. skillLevel[CONSTANTS.skill.Crafting] <
  683. Crafting.recipes[actionID].level
  684. )
  685. return false
  686. if (game.crafting.selectedRecipeID !== actionID)
  687. game.crafting.selectRecipeOnClick(actionID)
  688. if (game.activeSkill !== globalThis.ActiveSkills.CRAFTING)
  689. game.crafting.start(true)
  690. return true
  691. }
  692. case 'Firemaking':
  693. actionID = Firemaking.recipes.findIndex((x) => x.logID == itemID)
  694. return () => {
  695. if (
  696. skillLevel[CONSTANTS.skill.Firemaking] <
  697. Firemaking.recipes[actionID].levelRequired
  698. )
  699. return false
  700. if (
  701. !game.firemaking.activeRecipe ||
  702. game.firemaking.activeRecipe.logID !== actionID
  703. )
  704. game.firemaking.selectLog(actionID)
  705. if (!game.firemaking.isActive) game.firemaking.burnLog()
  706. return true
  707. }
  708. case 'Fishing': {
  709. const fish = Fishing.data.find((a) => a.itemID == itemID)
  710. const area = Fishing.areas.find((a) => a.fish.includes(fish))
  711. return () => {
  712. if (
  713. (!player.equipment.slotArray
  714. .map((a) => a.item.id)
  715. .includes(CONSTANTS.item.Barbarian_Gloves) &&
  716. area.id == 6) ||
  717. (!game.fishing.secretAreaUnlocked && area.id == 7) ||
  718. skillLevel[CONSTANTS.skill.Fishing] < fish.level
  719. )
  720. return false
  721. game.fishing.onAreaFishSelection(area, fish)
  722. if (
  723. game.activeSkill !== globalThis.ActiveSkills.FISHING ||
  724. game.fishing.activeFishingArea != area
  725. ) {
  726. game.fishing.onAreaStartButtonClick(area)
  727. }
  728. return true
  729. }
  730. }
  731. case 'Fletching':
  732. actionID = Fletching.recipes.find((a) => a.itemID == itemID).masteryID
  733. const log = items.findIndex((a) => a.name == skillItem2)
  734. if (skillItem1 != 'Arrow Shafts') {
  735. return () => {
  736. if (
  737. skillLevel[CONSTANTS.skill.Fletching] <
  738. Fletching.recipes[actionID].level
  739. )
  740. return false
  741. if (game.fletching.selectedRecipeID !== actionID)
  742. game.fletching.selectRecipeOnClick(actionID)
  743. if (game.activeSkill !== globalThis.ActiveSkills.FLETCHING)
  744. game.fletching.start()
  745. return true
  746. }
  747. }
  748. return () => {
  749. if (
  750. skillLevel[CONSTANTS.skill.Fletching] <
  751. Fletching.recipes[actionID].level ||
  752. !checkBankForItem(log)
  753. )
  754. return false
  755. if (
  756. game.fletching.selectedAltRecipe != log ||
  757. selectedFletch !== actionID
  758. )
  759. game.fletching.selectAltRecipeOnClick(log)
  760. if (game.activeSkill !== globalThis.ActiveSkills.FLETCHING)
  761. game.fletching.start()
  762. return true
  763. }
  764. case 'Herblore':
  765. actionID = Herblore.potions.findIndex((a) => a.name == skillItem1)
  766. return () => {
  767. if (
  768. skillLevel[CONSTANTS.skill.Herblore] <
  769. Herblore.potions[actionID].level
  770. )
  771. return false
  772. if (game.herblore.selectedRecipeID !== actionID)
  773. game.herblore.selectRecipeOnClick(actionID)
  774. if (!game.herblore.isActive) game.herblore.start()
  775. return true
  776. }
  777. case 'Mining':
  778. actionID = Mining.rockData.findIndex((a) => a.name == skillItem1)
  779. // game.mining.onRockClick(actionID)
  780.  
  781. return () => {
  782. if (
  783. (actionID === 9 && !game.mining.canMineDragonite) ||
  784. skillLevel[CONSTANTS.skill.Mining] <
  785. Mining.rockData[actionID].levelRequired
  786. )
  787. return false
  788. if (!game.mining.isActive || game.mining.selectedRockId != actionID)
  789. game.mining.onRockClick(actionID)
  790. return true
  791. }
  792. case 'Magic': {
  793. actionID = AltMagic.spells.findIndex((a) => a.name == skillItem1)
  794. const magicItem = items.findIndex((a) => a.name == skillItem2)
  795. return () => {
  796. if (skillLevel[CONSTANTS.skill.Magic] < AltMagic.spells[actionID].level)
  797. return false
  798. if (game.altMagic.selectedSpellID !== actionID)
  799. game.altMagic.selectSpellOnClick(actionID)
  800. switch (AltMagic.spells[actionID].consumes) {
  801. case 3:
  802. case 2:
  803. const bar = Smithing.recipes.find((a) => a.itemID == magicItem)
  804. if (skillLevel[CONSTANTS.skill.Smithing] < bar.level) return false
  805. if (game.altMagic.selectedSmithingRecipe != bar)
  806. game.altMagic.selectBarOnClick(bar)
  807. break
  808. case 1:
  809. case 0:
  810. if (game.altMagic.selectedConversionItem != magicItem)
  811. game.altMagic.selectItemOnClick(magicItem)
  812. break
  813. }
  814. if (!game.altMagic.isActive) game.altMagic.start()
  815. return true
  816. }
  817. }
  818. case 'Runecrafting':
  819. actionID = Runecrafting.recipes.findIndex((a) => a.itemID == itemID)
  820. return () => {
  821. if (
  822. skillLevel[CONSTANTS.skill.Runecrafting] <
  823. Runecrafting.recipes[actionID].level
  824. )
  825. return false
  826. if (game.runecrafting.selectedRecipeID !== actionID)
  827. game.runecrafting.selectRecipeOnClick(actionID)
  828. if (game.activeSkill !== globalThis.ActiveSkills.RUNECRAFTING)
  829. game.runecrafting.start(true)
  830. return true
  831. }
  832. case 'Smithing':
  833. actionID = Smithing.recipes.findIndex((a) => a.itemID == itemID)
  834. return () => {
  835. if (
  836. skillLevel[CONSTANTS.skill.Smithing] <
  837. Smithing.recipes[actionID].level
  838. )
  839. return false
  840. if (game.smithing.selectedRecipeID !== actionID)
  841. game.smithing.selectRecipeOnClick(actionID)
  842. if (!game.smithing.isActive) game.smithing.start()
  843. return true
  844. }
  845. case 'Summoning': {
  846. const summonID = Summoning.marks.findIndex((a) => a.itemID == itemID)
  847. let recipeID = 0
  848. if (options.actions['Start Skill']['Summoning'][skillItem1] != null) {
  849. const ingredientID = items.findIndex((a) => a.name == skillItem2)
  850. recipeID = Summoning.marks[summonID].nonShardItemCosts.findIndex(
  851. (a) => a == ingredientID
  852. )
  853. }
  854. return () => {
  855. //exit if low level
  856. if (
  857. skillLevel[CONSTANTS.skill.Summoning] <
  858. Summoning.marks[summonID].level
  859. )
  860. return false
  861. //if summon is not selected, choose it
  862. if (
  863. game.summoning.selectedRecipeID != summonID ||
  864. game.summoning.selectedAltRecipe != recipeID
  865. ) {
  866. game.summoning.selectRecipeOnClick(summonID)
  867. game.summoning.selectAltRecipeOnClick(recipeID)
  868. }
  869. if (game.activeSkill !== globalThis.ActiveSkills.SUMMONING)
  870. game.summoning.start()
  871. return game.activeSkill === globalThis.ActiveSkills.SUMMONING
  872. }
  873. }
  874. case 'Thieving': {
  875. const npc = Thieving.npcs.find((a) => a.name == skillItem1)
  876. const area = Thieving.areas.find((a) => a.npcs.includes(npc.id))
  877. const panel = thievingMenu.areaPanels.find((a) => a.area == area)
  878. return () => {
  879. if (skillLevel[CONSTANTS.skill.Thieving] < npc.level) return false
  880. if (
  881. game.activeSkill == globalThis.ActiveSkills.THIEVING &&
  882. game.thieving.currentNPC == npc
  883. )
  884. return true
  885. thievingMenu.selectNPCInPanel(npc, panel)
  886. game.thieving.startThieving(area, npc)
  887. return true
  888. }
  889. }
  890. case 'Woodcutting':
  891. actionID = [itemID, items.findIndex((a) => a.name == skillItem2)].slice(
  892. 0,
  893. playerModifiers.increasedTreeCutLimit + 1
  894. )
  895. return () => {
  896. let result = true
  897. let currentTrees = []
  898. game.woodcutting.activeTrees.forEach((a) => currentTrees.push(a.id))
  899. currentTrees.forEach((tree) => {
  900. if (actionID.includes(tree)) {
  901. actionID.splice(
  902. actionID.findIndex((a) => a == tree),
  903. 1
  904. )
  905. } else {
  906. actionID.unshift(tree)
  907. }
  908. })
  909.  
  910. actionID.forEach((i) => {
  911. if (
  912. skillLevel[CONSTANTS.skill.Woodcutting] >=
  913. Woodcutting.trees[i].levelRequired
  914. ) {
  915. game.woodcutting.selectTree(Woodcutting.trees[i])
  916. } else {
  917. result = false
  918. }
  919. })
  920. return result
  921. }
  922. }
  923. }
  924.  
  925. // ========================================================================== //
  926. // * footer
  927. // ========================================================================== //
  928.  
  929. function onGameReady(callback) {
  930. const foo = 'play-area-container'
  931. // const foo = 'status-action'
  932. const gameContainer = document.getElementsByClassName(foo)
  933. // gameContainer.length
  934. if (gameContainer.length === 0) {
  935. setTimeout(function () {
  936. onGameReady(callback)
  937. }, 500)
  938. } else {
  939. callback()
  940. }
  941. }
  942.  
  943. function init() {
  944. openDefaultPage(setDefaultPage[0])
  945. shortcuts()
  946. }
  947.  
  948. onGameReady(function () {
  949. init()
  950. })
  951. })()