Auto Familiar Bonding

Automatically bonds with your familiars. Has a GUI and some options for handling bonds.

当前为 2023-03-28 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Auto Familiar Bonding
// @version      1.2
// @description  Automatically bonds with your familiars. Has a GUI and some options for handling bonds.
// @author       Triggernometry
// @namespace    https://greasyfork.org/en/users/999683
// @match        https://www1.flightrising.com/dragon/*
// @match        https://www1.flightrising.com/lair/*
// @match        https://www1.flightrising.com/dragon-familiar/*
// @grant        GM_setValue
// @grant        GM_getValue
// @license      GNU GPLv3
// ==/UserScript==

// these are used across all/most functions
var toggleState = GM_getValue('toggleState', false);
var toggleDisplay = ["OFF (click to toggle)",
                         "ON (click to toggle)"];
var skipBondKey;
var skipBondStatus = GM_getValue('skipBondKey', 0);

var noFamKey;
var noFamStatus = GM_getValue('noFamKey', 0);

// finds the Bond window and closes it, then clicks "next"
function closeBond(nextDrag){
    // find close button, which has all of the following classes
    var xToClose = $(".ui-button.ui-corner-all.ui-widget.ui-button-icon-only.ui-dialog-titlebar-close");
    // if element is not NULL/undefined
    if (xToClose.length) {
        // close bond window
        xToClose.click();
        // go to Next Dragon link. no need to wait, since X doesn't re-load page like the Close button does
        window.open(nextDrag,"_self");
    }
    else {
        console.log("Not found!");
    }
}

//
function findNextDragon() {
    ;
}

function buildGUI() {
    // set up GUI box
    $('body').prepend("<div id=\"familiarbox\">" +
                      "    <div style=\"text-align: center; color: #e8cc9f; font: bold 7.8pt/30px tahoma; background: #731d08; margin: -10px -10px 10px;\">Auto Familiar Bonding</div>" +
                      // set toggle display to whatever it was before new page was loaded (or off, if page has never beeen loaded this session)
                      "    <button id=\"onOffDisplay\">" + toggleDisplay[toggleState ? 1 : 0] + "</button>" +
                      "</div>" +
                      "<style>" +
                      "    #familiarbox label {" +
                      "        float: inherit;" +
                      "    }" +
                      "    #familiarbox {" +
                      "        padding: 10px;" +
                      "        border: 1px solid #000;" +
                      "        position: fixed;" +
                      "        top: 0;" +
                      "        left: 0;" +
                      "        background: #fff;" +
                      "        z-index: 1002;" +
                      "    }" +
                      "    #turnOff," +
                      "    #turnOn {" +
                      "        border: 0;" +
                      "        background-color: #dcd6c8;" +
                      "        padding: 5px 10px;" +
                      "        color: #731d08;" +
                      "        margin: auto;" +
                      "        box-shadow: 0 1px 3px #999;" +
                      "        border-radius: 5px;" +
                      "        text-shadow: 0 1px 1px #FFF;" +
                      "        border-bottom: 1px solid #222;" +
                      "        cursor: pointer;" +
                      "        display: block;" +
                      "        font: bold 11px arial;" +
                      "        transition: 0.1s;" +
                      "    }" +
                      "    #onOffDisplay {" +
                      "        border: 0;" +
                      "        background-color: #dcd6c8;" +
                      "        padding: 5px 10px;" +
                      "        color: #731d08;" +
                      "        margin: auto;" +
                      "        box-shadow: 0 1px 3px #999;" +
                      "        border-radius: 5px;" +
                      "        text-shadow: 0 1px 1px #FFF;" +
                      "        border-bottom: 1px solid #222;" +
                      "        cursor: pointer;" +
                      "        display: block;" +
                      "        font: bold 11px arial;" +
                      "        transition: 0.1s;" +
                      "    }" +
                      "    #turnOff:hover," +
                      "    #turnOn:hover {" +
                      "        background-color: #bfb9ac;" +
                      "        color: #731d08;" +
                      "    }" +
                      "</style>"
                     );

    // add 'Already Bonded' options
    $('#familiarbox').append("<br>If already bonded..." +
                             "<br>" +
                             "<form id=\"alreadybondedform\">" +
                             "	<input type=\"radio\"" +
                             "		   id=\"skipbond\"" +
                             "		   name=\"alreadybonded\">" +
                             "	<label for=\"skipbond\">Skip to next Dragon</label>" +
                             "	<br>" +
                             "	<input type=\"radio\"" +
                             "		   id=\"stopbond\"" +
                             "		   name=\"alreadybonded\">" +
                             "	<label for=\"stopbond\">Stop</label>" +
                             "</form>"
                            );


    // set behavior for 'Already Bonded' radio buttons
    $("#alreadybondedform").change(function() {
        if($('#skipbond').is(':checked')) {
            GM_setValue('skipBondKey', true);
        }
        //// currently unnecessary, but left as-is to provide template
        //else if($('#stopbond').is(':checked')) {
        //    GM_setValue('skipBondKey',false);
        //}
        else {
            GM_setValue('skipBondKey', false);
        }
    });


    if (skipBondStatus == true) {
        $( "#skipbond" ).prop( "checked", true );
    }
    else {
        $( "#stopbond" ).prop( "checked", true );
    }

    // add 'No Familiar' options
    $('#familiarbox').append("<br>If No Familiar..." +
                             "<br>" +
                             "<form id=\"nofamform\">" +
                             "    <input type=\"radio\"" +
                             "           id=\"addfam\"" +
                             "           name=\"nofam\">" +
                             "    <label for=\"addfam\">Add Familiar</label>" +
                             "    <br>" +
                             "    <input type=\"radio\"" +
                             "           id=\"skipfam\"" +
                             "           name=\"nofam\">" +
                             "    <label for=\"skipfam\">Skip to next Dragon</label>" +
                             "    <br>" +
                             "    <input type=\"radio\"" +
                             "           id=\"stopfam\"" +
                             "           name=\"nofam\">" +
                             "    <label for=\"stopfam\">Stop</label>" +
                             "</form>"
                            );

    // set behavior for 'No Familiar' radio buttons
    if (noFamStatus == 'addfam') {
        $( "#addfam" ).prop( "checked", true );
    }
    else if (noFamStatus == 'skipfam') {
        $( "#skipfam" ).prop( "checked", true );
    }
    else if (noFamStatus == 'stopfam') {
        $( "#stopfam" ).prop( "checked", true );
    }
    // by default
    else {
        $( "#stopfam" ).prop( "checked", true );
    }


    $("#nofamform").change(function() {
        if($('#addfam').is(':checked')) {
            GM_setValue('noFamKey','addfam');
        }
        else if($('#skipfam').is(':checked')) {
            GM_setValue('noFamKey','skipfam');
        }
        else if($('#stopfam').is(':checked')) {
            GM_setValue('noFamKey','stopfam');
        }
    });

    // set the toggle click behavior
    $('#onOffDisplay').click(function(){
        toggleState = !toggleState;
        GM_setValue('toggleState', toggleState);

        console.log(toggleState);

        if(toggleState) {
            $('#onOffDisplay').html(toggleDisplay[1]);
        }
        else {
            $('#onOffDisplay').html(toggleDisplay[0]);
        }
    });
}

function main() {
    buildGUI();

    // on, and on a dragon profile page, and NOT on a hibDen dragon
    if (toggleState == true && window.location.href.includes("/dragon/") && Object.values($(".breadcrumbs > a")).every( (link) => link.text != "Hibernal Den" ) ) {
        // find the next dragon's link
        const nextDrag = $('#dragon-profile-dragon-next').attr("href");
        // seach link for HibDen
        const isBelowThreshold = (link) => link.text != "Hibernal Den";


        // if the id= exists, if dragon has a familiar
        if( $('#dragon-profile-familiar-image').length ) {
            // if already bonded
            if( $('img[src="/static/layout/profile/button-bond-disabled.png"]').length ) {
                // if already bonded
                console.log("already bonded");
                if (skipBondStatus == true) {
                    window.open(nextDrag,"_self");
                }
            } else {
                // click the 'bond' button with id=
                $("#dragon-profile-button-bond").click();

                setInterval(closeBond, 1000, nextDrag);

            }
        }
        // if dragon has no familiar...
        else {
            if (noFamStatus == 'addfam') {
                // if dragon has no familiar... add a familiar
                $('#dragon-profile-button-switch-familiar .common-ui-button').click();
            } else if (noFamStatus == 'skipfam') {
                // if dragon has no familiar... skip to next dragon
                window.open(nextDrag,"_self")
            } else if (noFamStatus == 'stopfam') {
                // if dragon has no familiar... stop

                new Notification("Auto Familiar Bonding stopped because dragon has no familiar.");
            }
        }
    }
}

// wait until page load, then run main
$(document).ready(main);