description
目前為
// ==UserScript==
// @name Faction Challenge Totals
// @namespace namespace
// @version 0.3
// @description description
// @author tos
// @match *.torn.com/factions.php*
// ==/UserScript==
$( document ).ajaxComplete(function(event, jqXHR, ajaxObj) {
if (ajaxObj.data && ajaxObj.data.includes('step=upgradeConfirm')) {
const resp = JSON.parse(jqXHR.responseText)
let challenge_total = 0
if (resp.contributors) {
for (const group of resp.contributors) {
for (const member of Object.keys(group)) {
challenge_total += parseInt(group[member].total.replace(',', ''))
}
}
document.querySelector('#stu-confirmation .buttons-wrap').insertAdjacentHTML('beforeend', `<div class="name">Challenge Total: ${numberWithCommas(challenge_total)}</div>`)
}
}
})
function numberWithCommas(x) {
var parts = x.toString().split(".");
return parts[0].replace(/\B(?=(\d{3})+(?=$))/g, ",") + (parts[1] ? "." + parts[1] : "");
}