Graphomata Leaderboard Weighted Score Display

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

当前为 2024-02-27 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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';
})();