Company Max Withdrawal Calculator

Calculates the maximum amount you can withdraw from the company bank.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Company Max Withdrawal Calculator
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Calculates the maximum amount you can withdraw from the company bank.
// @author       LordBusiness [2052465]
// @match        https://www.torn.com/companies.php
// @grant        none
// ==/UserScript==

//Insert Your Torn API key here .. e.g. var APIkey = "HkU48qd86vjkNHaO";
var APIkey = "";

// a minimal jQuery library for reacting to innerHTML changes
(function($) {
  $.fn.change = function(cb, e) {
    e = e || { subtree:true, childList:true, characterData:true };
    $(this).each(function() {
      function callback(changes) { cb.call(node, changes, this); }
      var node = this;
      (new MutationObserver(callback)).observe(node, e);
    });
  };
})(jQuery);

var url = "https://api.torn.com/company/?selections=employees&key=" + APIkey;
$("#ui-id-10").click(function() {
    $('#funds').change(function(changes, observer) {
            try {
                var sum = 0;
                if((changes.length == 11) && ($("#funds > .withdraw").find(".m-bottom5").length == 1)) {
                    $.getJSON( url )
                        .done(function( json ) {
                        sum = 0;
                        for (var key in json.company_employees) {
                            sum += parseInt(json.company_employees[key].wage);
                        }
                        var maxWithdraw = $("#funds > .withdraw").find(".bold").text();
                        maxWithdraw = /\$[0-9,]+/gm.exec(maxWithdraw);
                        maxWithdraw = parseInt(maxWithdraw[0].replace(/[^0-9]/g, ''));
                        $("#funds > .withdraw").find(".m-bottom5").html("You can withdraw a maximum of $" + (maxWithdraw - (sum * 7)).toLocaleString());
                    })
                        .fail(function( jqxhr, textStatus, error ) {
                        var err = textStatus + ", " + error;
                        console.log( "Request Failed: " + err );
                    });
                }

            }
            catch(err) {
                console.log("Err:" + err);
            }
        });
});

console.log("Made by LordBusiness.");