Flight Rising Baldwin

Automatically transmutes items from your list.

当前为 2022-12-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Flight Rising Baldwin
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Automatically transmutes items from your list.
  6. // @author Triggernometry
  7. // @match https://www1.flightrising.com/trading/baldwin/transmute*
  8. // @grant none
  9. // @license GNU GPLv3
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. getState();
  15. })();
  16.  
  17. // Categories are food, mats, app, fam, other
  18.  
  19. let transmuteItems = {
  20. 'food' : ['Albino Dasher', 'Common Sparrow', 'Red Squirrel'],
  21. 'mats' : ['Bone Fragments', 'Sparrow Skull', 'Crumbling Leather', 'Birch Logs', 'Fir Logs', 'Shattered Ceramic Shards'],
  22. 'app' : [],
  23. 'fam' : [],
  24. 'other' : ['Broken Clay Pot']
  25. };
  26.  
  27. function getState(){
  28.  
  29. let idle = document.querySelector('#plus-button-container');
  30. let brewing = document.querySelector('.baldwin-cauldron-brewing');
  31. let done = document.querySelector('.baldwin-cauldron-done');
  32.  
  33. if(done){
  34. collectItem();
  35. } else if (brewing){
  36. brewingWait();
  37. } else if(idle){
  38. transmute();
  39. }
  40. }
  41.  
  42. async function collectItem(){
  43. let collectDoneItem = document.querySelector('input[value="Collect!"]').click();
  44. // wait for page to load after click
  45. // await collectDoneItem.DOMContentLoaded();
  46. await sleep(2000);
  47. location.reload();
  48. }
  49.  
  50. async function brewingWait(){
  51. let brewingTime = document.querySelector('#baldwin-timer-value').getAttribute('data-seconds-left');
  52. brewingTime = parseInt(brewingTime) + 3;
  53. console.log(`Now waiting for ${brewingTime} seconds. Please Stand by.`)
  54. await sleep(brewingTime * 1000);
  55. location.reload();
  56. }
  57.  
  58. async function transmute(){
  59. let clickTransmuteButton = document.querySelector('#plus-button').click();
  60. console.log(`Click return object: ${clickTransmuteButton}`)
  61. // wait for item load
  62. // await clickTransmuteButton.DOMContentLoaded();
  63. await sleep(2000);
  64. //console.log(`${transmuteItem[0]} : ${transmuteItem[1]}`)
  65. let transmuteSelection;
  66.  
  67. for (const key of Object.keys(transmuteItems)) {
  68. let valueList = transmuteItems[key];
  69. console.log("key:", key);
  70. // switch to category tab
  71. let chooseCategory = document.querySelector(`#swaptabs > a[data-tab-id="${key}"]`).click();
  72. await sleep(2000);
  73.  
  74. // get all items in category
  75. let itemList = document.querySelectorAll('#itempage > span > a');
  76.  
  77. // compare to own list of allowed items
  78. for (const node of itemList) {
  79. if(valueList.includes(node.getAttribute('data-name'))) {
  80. // if allowed item found, set and break loop
  81. transmuteSelection = node;
  82. break;
  83. }
  84. }
  85.  
  86. // if not null, we found a good value. break outer loop
  87. if (transmuteSelection) {
  88. break;
  89. }
  90. }
  91. // if not null, item found
  92. if(transmuteSelection) {
  93. transmuteSelection.click();
  94. await sleep(1000);
  95. let transmuteStart = document.querySelector('#attch').click();
  96. await sleep(2000);
  97. let transmuteConfirm = document.querySelector('#transmute-confirm-ok').click();
  98. }
  99. // otherwise, reached end of items without findin a match. Exit.
  100. else {
  101. console.log("Reached end without finding a match. Nothing to brew.");
  102. return 0;
  103. }
  104. }
  105.  
  106. function sleep(ms) {
  107. return new Promise(resolve => setTimeout(resolve, ms));
  108. }