GOTA_Extender_Constants

Constants definition.

目前為 2014-10-10 提交的版本,檢視 最新版本

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

var templates = {
    menuBtn:
        '<a id="extender-menu" class="navlink" data-menu="manager">' +
            '<span class="navlinkbox">' +
            '<span class="navlinkicon"></span>' +
            '<span class="vertcenter">' +
            '<span>Extender</span>' +
            '</span>' +
            '</span>' +
            '</a>',

    queueBtn:
        '<span class="btnwrap btnmed equipbtn queue" data-quantity="1">' +
            '<span class="btnedge">' +
            '<a class="btngold">Queue</a>' +
            '</span>' +
            '</span>',
    
    queue5Btn:
        '<span class="btnwrap btnmed equipbtn queue" data-quantity="5">' +
            '<span class="btnedge">' +
            '<a class="btngold">Queue x5</a>' +
            '</span>' +
            '</span>',

    queueUpgradeBtn:
        '<h5>Actions:</h5>' +
            '<div class="upgradeinfo">' +
            '<span id="upgradeQueue" class="btnwrap btnmed btnprice upgradeQueue">' +
            '<span class="btnedge">' +
            '<a class="btngold">Enqueue upgrade</a>' +
            '</span>' +
            '</span>' +
            '</div>',

    saveOptionsBtn:
        '<span id="saveOptions" class="btnwrap btnlg">' +
            '<span class="btnedge">' +
            '<a class="btngold">Save</a>' +
            '</span>' +
            '</span>',

    resetOptionsBtn:
        '<span id="resetOptions" class="btnwrap btnlg">' +
            '<span class="btnedge">' +
            '<a class="btngold">Reset</a>' +
            '</span>' +
            '</span>',

    observable:
        '<textarea id="observable" rows="1" style="width:99%; overflow:auto; display: none;"></textarea>',

    tabContent:
        '<div id="extenderTabContent" style="margin-top: 18px;"></div>',

    optionsHeader:
        '<h1 style="font-family:GoudyTrajan-Bold,Trajan,\'Trajan Pro\',Trajanbold;">Extender options</h1><hr />' +
            '<div id="extenderTabMenu" style="margin: 0 0 0;">' +
            '<div class="charactertabs"></div>' +
            '<div class="barbtmedge"></div>' +
            '</div>',

    tableSkeleton:
        '<div style="overflow-y: auto; height: 380px;">' +
            '<table id="queueTable" class="powertable">' +
            '<tbody>' +
            '<tr id="headerRow">' +
            '<th id="col4"><span class="colsort">QueueID</span></th>' +
            '<th id="col1"><span class="colsort">Type</span></th>' +
            '<th id="col1"><span class="colsort">Building</span></th>' +
            '<th id="col2"><span class="colsort">Name</span></th>' +
            '<th id="col3"><span class="colsort">Icon</span></th>' +
            '</tr>' +
            '</tbody>' +
            '</table>' +
            '</div>',

    bruteBtn:
        '<span id="bruteBtn" class="btnwrap btnmed" style="margin-top: 6px;">' +
            '<span class="btnedge">' +
            '<a class="btngold">Brute!</a>' +
            '</span>' +
            '</span>',

    finishAllBtn:
        '<span class="btnwrap btnlg" onclick="finishAll()"><span class="btnedge"><a class="btngold">Finish All Buildings</a></span></span>',

    checkOption: function (id, name, val) {
        return '<a style="color:white;" id="' + id + '" class="extender-option checkbox ' + (val ? 'checked' : '') + '" onclick="check(this)">' + name + '</a>';
    },

    numberOption: function (id, label, val, min, max, step) {
        return '<label for="' + id + '">' + label + '</label>' +
            '<span id="' + id + '" ' +
            'class="extender-option extender-number" ' +
            'min="' + min + '" ' +
            'max="' + max + '" ' +
            'step="' + step + '"' +
            'onclick="increment(this)">' + val + '</span>';
    },

    sellBulkBtn: function (itemId) {
        return '<span class="sellbulk">' +
            '<input type="number" id="sell_bulk_amount" placeholder="Amount">' +
            '<span id="do_sell_bulk" class="btnwrap btnsm" item-id="' + itemId + '">' +
            '<span class="btnedge">' +
            '<a class="btngold">Sell</a>' +
            '</span></span></span>';
    },

    optionsTab: function (id, name) {
        return '<span id="' + id + '" class="inventorytabwrap">' +
            '<span class="inventorytabedge">' +
            '<a class="inventorytab" style="padding: 1px 15px 0 15px; !important">' +
            name +
            '<em></em>' +
            '</a>' +
            '</span></span>';
    },

    tableRow: function (i, el) {
        return '<tr class="tableRow" style="cursor: pointer">' +
            '<td><span class="ranklist colsort">' + i + '</span></td>' +
            '<td><span class="ranklist colsort">' + el.type + '</span></td>' +
            '<td><span class="name colsort">' + el.activeBuildingPanel + '</span></td>' +
            '<td><span class="name colsort">' + el.name + '</span></td>' +
            '<td><span class="avatarimg"><img src="' + el.img + '"></span></td>' +
            '</tr>';
    },

    mainTab: function (o) {
        return '<div class="exrow">' +
            this.checkOption("toggledebugModes", "Debug mode", o.debugMode) +
            this.checkOption("toggleAutoCollect", "Enable auto-collecting", o.autoCollect) +
            '</div>' +
            '<div class="exrow">' +
            this.numberOption("autoCollectInterval", "Collect in (minutes): ", o.autoCollectInterval, 30, 360, 30) +
            this.finishAllBtn +
            '</div>';
    },

    queueTab: function (o) {
        return '<div class="exrow">' +
            this.numberOption("queueDelay", "Delay in (seconds):", o.queueDelay, 4, 20, 4) +
            this.checkOption("toggleSuperiorMaterials", "Use superior materials", o.superiorMaterials) +
            '</div>' +
            '<div class="exrow">' +
            this.numberOption("queueTimerInterval", "Interval in (minutes):", o.queueTimerInterval, 0, 240, 30) + '(0 = disabled)' +
            '</div><hr/>' +
            this.tableSkeleton;
    },

    bruteTab: function (o) {
        return '<div class="exrow">' +
            this.numberOption("bruteWounds", "Brute until: ", o.bruteWounds, 0, 4, 1) + 'wound(s) (0 = disabled) and then: ' +
            '<span class="btnwrap btnlg" id="bruteSwitchOff" onclick="bruteSwitchToggle(this)"><span class="btnedge"><a class="btngold">' + (o.bruteSwitchOff ? 'switch off' : 'adjust') + '</a></span></span>' +
            '</div>';
    },
};

var styles = {
    resetOptions:
        '#resetOptions { ' +
            'bottom: 15px; ' +
            'left: 66%; ' +
            'margin-left: -40px; ' +
            'padding: 0; ' +
            'position: absolute; ' +
            'width: 80px; ' +
            '}',

    saveOptions:
        '#saveOptions {' +
            'bottom: 15px;' +
            'left: 34%;' +
            'margin-left: -40px; ' +
            'padding: 0; ' +
            'position: absolute; ' +
            'width: 80px; ' +
            '}',

    extenderMenu:
        '#extender-menu .navlinkicon {' +
            'background-image: url("http://disruptorbeamcdn-01.insnw.net/images/icons/newnav-menu.png?t=386c1688da2a"); ' +
            '}',

    extenderTabMenu:
        '#extenderTabMenu {' +
            'background: url("http://disruptorbeamcdn-01.insnw.net/images/character/horzmenubg.png?t=074863387615") repeat-x scroll 0 bottom #000;' +
            'height: 46px;' +
            'margin: 0px 6px 0px;' +
            'position: relative;' +
            'text-align: center;' +
            'width: auto;' +
            '}',

    exRow:
        '.exrow {' +
            'margin: 8px 0 0;' +
            '}',

    exOption:
        '.extender-option {' +
            'margin: 0 10px 0 8px;' +
            '}',
    exNumber:
        '.extender-number {' +
            'background: url("http://disruptorbeamcdn-01.insnw.net/images/city/buildinglvl.png?t=7e85013c75ef") no-repeat scroll 0 0 transparent;' +
            'color: #d6b97a;' +
            'display: inline-block;' +
            'font-family: GoudyTrajan-Bold,Trajan,"Trajan Pro",Trajanbold;' +
            'font-weight: bold;' +
            'height: 32px;' +
            'line-height: 32px;' +
            'right: 5px;' +
            'text-align: center;' +
            'top: 70px;' +
            'width: 33px;' +
            'cursor: pointer;' +
            '}',

    sellBulk:
        '.sellbulk {' +
            'color: white;' +
            'position: relative;' +
            '} ' +
            '.sellbulk input {' +
            'background-color: #000;' +
            'border: 1px solid #444;' +
            'border-radius: 5px;' +
            'color: white;' +
            'padding: 5px;' +
            'width: 100px;' +
            '}',

    addAllStyles: function () {

        try {

            var elmHead, elmStyle;
            elmHead = document.getElementsByTagName('head')[0];
            elmStyle = document.createElement('style');
            elmStyle.type = 'text/css';
            elmHead.appendChild(elmStyle);            
            for (var style in this) {
                if (this.hasOwnProperty(style) && typeof this[style] == "string") {
                    elmStyle.innerHTML
                    ? elmStyle.innerHTML += "\n" + this[style]
                    : elmStyle.innerHTML = this[style];
                }
            }

        } catch (e) {
            warn("Error occured: " + e + ". Retrying... ");

            if (!document.styleSheets.length)
                document.createStyleSheet();

            for (var cStyle in this) {
                if (this.hasOwnProperty(cStyle) && typeof this[cStyle] == "string") {
                    document.styleSheets[0].cssText
                        ? document.styleSheets[0].cssText += "\n" + this[cStyle]
                        : document.styleSheets[0].cssText = this[cStyle];
                }
            }
        }
    }
};

var auxiliary = {
    increment: function increment(me) {
        var opt = $(me);

        var min = parseInt(opt.attr("min"));
        var max = parseInt(opt.attr("max"));
        var step = parseInt(opt.attr("step"));
        var val = parseInt(opt.text());

        if (isNaN(min) || isNaN(max) || isNaN(step) || isNaN(val)) {
            return;
        }

        var newVal = val + step > max ? min : val + step;
        opt.text(newVal);
    },

    check: function check(me) {
        $(me).toggleClass('checked');
    },

    bruteSwitchToggle: function bruteSwitchToggle(me) {
        var bSwitch = $(me).find("a.btngold");
        bSwitch.text() == "switch off"
        ? bSwitch.text("adjust")
        : bSwitch.text("switch off");
    }
};