Flight Rising Auto-Baldwin

Automatically transmutes items from your list

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Flight Rising Auto-Baldwin
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Automatically transmutes items from your list
// @author       Triggernometry
// @match        https://www1.flightrising.com/trading/baldwin/transmute*
// @grant        none
// @license      GNU GPLv3
// ==/UserScript==

(function() {
    'use strict';
    getState();
})();

// Categories are food, mats, app, fam, battle, skins, specialty, other

let transmuteItems = {
    'food'      : ['Albino Dasher', 'Common Sparrow', 'Red Squirrel'],
    'mats'      : ['Bone Fragments', 'Sparrow Skull', 'Crumbling Leather', 'Birch Logs', 'Fir Logs', 'Shattered Ceramic Shards'],
    'app'       : [],
    'fam'       : [],
    'battle'    : [],
    'skins'     : [],
    'specialty' : [],
    'other'     : ['Broken Clay Pot']
};

function getState(){

    let idle = document.querySelector('#plus-button-container');
    let brewing = document.querySelector('.baldwin-cauldron-brewing');
    let done = document.querySelector('.baldwin-cauldron-done');

    if(done){
        collectItem();
    } else if (brewing){
        brewingWait();
    } else if(idle){
        transmute();
    }
}

async function collectItem(){
    let collectDoneItem = document.querySelector('input[value="Collect!"]').click();
    // wait for page to load after click
    // await collectDoneItem.DOMContentLoaded();
    await sleep(2000);
    location.reload();
}

async function brewingWait(){
    let brewingTime = document.querySelector('#baldwin-timer-value').getAttribute('data-seconds-left');
    brewingTime = parseInt(brewingTime) + 3;
    console.log(`Now waiting for ${brewingTime} seconds. Please Stand by.`)
    await sleep(brewingTime * 1000);
    location.reload();
}

async function transmute(){
    let clickTransmuteButton = document.querySelector('#plus-button').click();
    // wait for item load
    // await clickTransmuteButton.DOMContentLoaded();
    await sleep(2000);
    //console.log(`${transmuteItem[0]} : ${transmuteItem[1]}`)
    let transmuteSelection;

    for (const key of Object.keys(transmuteItems)) {
        let valueList = transmuteItems[key];
        console.log("key:", key);
        // switch to category tab
        let chooseCategory = document.querySelector(`#swaptabs > a[data-tab-id="${key}"]`).click();
        await sleep(2000);

        // get all items in category
        let itemList = document.querySelectorAll('#itempage > span > a');

        // compare to own list of allowed items
        for (const node of itemList) {
            if(valueList.includes(node.getAttribute('data-name'))) {
                // if allowed item found, set and break loop
                transmuteSelection = node;
                break;
            }
        }

        // if not null, we found a good value. break outer loop
        if (transmuteSelection) {
            break;
        }
    }
    transmuteSelection.click();
    await sleep(1000);
    let transmuteStart = document.querySelector('#attch').click();
    await sleep(2000);
    let transmuteConfirm = document.querySelector('#transmute-confirm-ok').click();
}

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}