Graphomata Leaderboard Weighted Score Display

Display weighted score (i.e. Re+½Im) at the leaderboard.

目前為 2024-02-27 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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';
})();