Skip to content

Instantly share code, notes, and snippets.

@pisaiah
Created November 23, 2024 05:32
Show Gist options
  • Save pisaiah/7fce1aa1e5207c009305942483984d37 to your computer and use it in GitHub Desktop.
Save pisaiah/7fce1aa1e5207c009305942483984d37 to your computer and use it in GitHub Desktop.
userscript for Authors Curseforge
// BetterACF
var boxes;
var days = 0;
var total = 0.0;
var month_short = ["Jan","Feb","Mar","April","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"];
var current_month = new Date().getMonth() + 1;
function do_stuff() {
var el = document.querySelector('.css-1q7977g')
if (el == undefined) {return;}
el.style.outline = "0"
el.style.display = "none"
make_boxes();
boxes[0].innerHTML = boxh(`+$ ${(total).toFixed(2)}`, `Last ${days} Day Gain`)
}
function make_boxes() {
var htmll = `<style>
.css-1q7977g {display:none}.css-gg4vpm {display:block;}.css-gg4vpm p {max-width: 100vw !important;}
.mybox {
vertical-align: middle;
display:inline-block;
border:1px solid rgb(51,51,51);
border-radius:1px;
padding:12px;
margin-top:14px;
margin-right:12px;
font-size:20px;
background: rgba(255, 255, 255, 0.08);
}
.subt{color:rgb(170,170,170);font-size:12px;}</style>`
var pa = document.querySelector('.css-gg4vpm')
if (undefined == pa) {
setTimeout(make_boxes, 10);
return;
}
var box = document.querySelector('#my-custom-box')
if (document.querySelectorAll('#my-custom-box').length == 0) {
box = document.createElement('div')
box.setAttribute('id', 'my-custom-box')
pa.appendChild(box)
}
boxes = document.querySelectorAll('.mybox');
var needed_boxes = 9;
if (boxes.length != needed_boxes) {
for (var i = 0; i < needed_boxes; i++) {
htmll += nbox('', "Loading...")
}
box.innerHTML = htmll;
}
boxes = document.querySelectorAll('.mybox');
}
function i_set_ev() {
var ars = document.querySelectorAll('td.css-160iszy div')
for (var ar of ars) {
if (ar.style.outline.indexOf('solid') != -1) {ar.addEventListener("click", i_do_all); }
ar.style.outline = "1px solid rgb(240,100,50)";
}
}
function i_do_proj() {
var pps = document.querySelectorAll('div.css-1jfg054 span')
for (var ppel of pps) {
if (ppel.innerText.indexOf('for') != -1) continue;
var txt = ppel.innerText.split("(")[0].trim();
ppel.innerHTML = txt + " (<i style='color:rgb(0,200,0)'>$" + (parseFloat(txt) * 0.05).toFixed(2) + "</i>)"
}
}
function i_changee() {
var cdays = 0;
var ctotal = parseFloat(0.0);
var stuff = document.querySelectorAll('.css-1pseopm');
var month_days = 0;
var month_total = 0;
for (var ch of stuff) {
ch.style.border = "0";
var txt = ch.innerText.split("(")[0].trim()
if (txt.indexOf(' ') != -1 || isNaN(txt)) continue;
var row = ch.parentElement.parentElement;
var month = parseInt(row.children[4].innerText.split(', ')[0].split('/')[0])
var col1 = row.children[1];
if (col1.innerText.indexOf('generat') == -1) {
continue;
}
var vall = parseFloat(txt);
var color = " (<i style='color:rgb(0,200,0)'>$" + (vall * 0.05).toFixed(2) + "</i>)";
row.children[2].innerHTML = color; // "Value" field
ch.innerHTML = txt + color;
cdays += 1;
ctotal = ctotal + vall
if (month == current_month) {
month_days += 1;
month_total += vall;
}
}
if (ctotal > 0) {
days = cdays;
total = ctotal * 0.05
boxes[0].innerHTML = boxh(`+$${(total).toFixed(2)}`, `Last ${cdays} Day Gain`)
boxes[1].innerHTML = boxh(`+$${(month_total * 0.05).toFixed(2)}`, `${month_short[current_month-1]} <span style='font-size:.7rem'>(Last ${month_days} Days)</span>`)
var per_day = ((month_total / month_days) * (30 - month_days)) + month_total
boxes[2].innerHTML = boxh(`~+$${(per_day * 0.05).toFixed(2)}`, `${month_short[current_month-1]} <span style='font-size:.7rem'>(Estimate)</span>`)
i_req();
}
}
var myObj;
function i_req() {
if (undefined != myObj) {
i_doo_lmr(myObj);
return;
}
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myObj = JSON.parse(this.responseText);
i_doo_lmr(myObj);
}
};
req.open("GET", "https://authors.curseforge.com/_api/statistics/queries/lastMonthRevenue", true);
req.send();
}
function i_doo_lmr(myObj) {
var arr = myObj['queryResult']['data'];
for (var i = arr.length - 1; i >= 0; i -= 1) {
var dat = arr[i];
var monthh = month_short[new Date(dat.revenueDate).getUTCMonth()];
boxes[2 + (arr.length - i)].innerHTML = boxh(`+$${dat.revenue}`, `${monthh}`)
}
}
function boxh(a, b) { return a + "<br><span class='subt'>" + b + "</span></div>"; }
function nbox(a, b) { return "<div class='mybox'>" + a + "<br><span class='subt'>" + b + "</span></div>" }
function i_do_all() { i_do_proj(); setTimeout(i_do_proj, 2000); }
function i_every() { do_stuff(); i_changee(); i_do_proj(); i_set_ev(); }
// Do stuff
setTimeout(make_boxes, 10);
setTimeout(i_every, 1000)
setInterval(i_set_ev(), 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment