Display weighted score (i.e. Re+½Im) at the leaderboard.
当前为
// ==UserScript==
// @name Graphomata Leaderboard Weighted Score Display
// @description Display weighted score (i.e. Re+½Im) at the leaderboard.
// @namespace http://tampermonkey.net/
// @version 2024-02-27
// @author WYXkk
// @match https://graphomata.com/game/leaderboards.html
// @icon https://www.google.com/s2/favicons?sz=64&domain=graphomata.com
// @grant none
// @license MIT
// ==/UserScript==
function fromHTML(html, trim = true) {
html = trim ? html.trim() : html;
if (!html) return null;
const template = document.createElement('template');
template.innerHTML = html;
const result = template.content.children;
if (result.length === 1) return result[0];
return result;
}
// from https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro
async function untilGet(id)
{
var u=undefined;
while(u==undefined)
{
u=document.querySelectorAll(id)[0];
await new Promise(resolve => setTimeout(resolve, 100));
}
return u;
}
(async function() {
'use strict';
var a=await untilGet('#leaderboardsTable > tbody');
let top=a.children[0];
top.insertBefore(fromHTML('<th>Weighted</th>'),top.children[2]);
for(let i=1;i<a.childElementCount;i++){
let x=a.children[i];
let score=x.children[1].innerText;
let parsedScore=score.replaceAll('i','').replaceAll(',','').split('+').map(t=>parseInt(t));
let value=parsedScore[0]+(parsedScore[1]?parsedScore[1]:0)/2;
x.insertBefore(fromHTML(`<td style="white-space: nowrap">${value.toLocaleString()}</td>`),x.children[2]);
}
document.body.style['maxWidth']='950px';
})();