Skip to content

Instantly share code, notes, and snippets.

@skyghis
Last active May 21, 2024 07:21
Show Gist options
  • Save skyghis/780914681028f6b4ea39bd2097cbe9dd to your computer and use it in GitHub Desktop.
Save skyghis/780914681028f6b4ea39bd2097cbe9dd to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Ygg affichage crédit (Go disponibles)
// @version 1.3.7
// @description Ajoute un compteur de crédit a gauche des compteurs d'upload et de download
// @namespace https://gist.github.com/skyghis/780914681028f6b4ea39bd2097cbe9dd
// @updateURL https://gist.github.com/skyghis/780914681028f6b4ea39bd2097cbe9dd/raw
// @match https://*ygg.*/*
// @icon https://www.ygg.re/favicon.ico
// @author SkyghiS
// @homepageURL https://gist.github.com/skyghis/780914681028f6b4ea39bd2097cbe9dd
// @run-at document-idle
// ==/UserScript==
function update() {
const parent = document.querySelector("div.ct:nth-child(2) > ul:nth-child(1) > li:nth-child(1)");
if (parent) {
const up = getGo(parent.querySelector("strong:nth-child(1)").innerText);
const dl = getGo(parent.querySelector("strong:nth-child(2)").innerText);
const credit = (up - dl);
//const ra = parent.querySelector("a:nth-child(1) > strong:nth-child(1)").innerText;
//const credit = (up - (up / ra));
const html = '<strong style="color:#98e3da"><span class="ico_thumbs-up"></span> ' + credit.toFixed(2) + ' Go</strong> - ';
parent.innerHTML = html + parent.innerHTML;
}
}
function getGo(amountAndUnit /* : xxxGo or xxxTo */) {
const amount = amountAndUnit.trim().slice(0, -2);
const unit = amountAndUnit.trim().slice(-2).slice(0, 1);
if (unit === 'T') {
return amount * 1024;
} else {
return amount;
}
}
update();
// Update on login
document.getElementById("user-login")?.addEventListener("submit", () => window.setTimeout(update, 1000));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment