Graphomata Leaderboard Weighted Score Display

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

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

  1. // ==UserScript==
  2. // @name Graphomata Leaderboard Weighted Score Display
  3. // @description Display weighted score (i.e. Re+½Im) at the leaderboard.
  4. // @namespace http://tampermonkey.net/
  5. // @version 2024-02-27
  6. // @author WYXkk
  7. // @match https://graphomata.com/game/leaderboards.html
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=graphomata.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. function fromHTML(html, trim = true) {
  14. html = trim ? html.trim() : html;
  15. if (!html) return null;
  16.  
  17. const template = document.createElement('template');
  18. template.innerHTML = html;
  19. const result = template.content.children;
  20.  
  21. if (result.length === 1) return result[0];
  22. return result;
  23. }
  24. // from https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro
  25.  
  26. async function untilGet(id)
  27. {
  28. var u=undefined;
  29. while(u==undefined)
  30. {
  31. u=document.querySelectorAll(id)[0];
  32. await new Promise(resolve => setTimeout(resolve, 100));
  33. }
  34. return u;
  35. }
  36.  
  37. (async function() {
  38. 'use strict';
  39. var a=await untilGet('#leaderboardsTable > tbody');
  40. let top=a.children[0];
  41. top.insertBefore(fromHTML('<th>Weighted</th>'),top.children[2]);
  42. for(let i=1;i<a.childElementCount;i++){
  43. let x=a.children[i];
  44. let score=x.children[1].innerText;
  45. let parsedScore=score.replaceAll('i','').replaceAll(',','').split('+').map(t=>parseInt(t));
  46. let value=parsedScore[0]+(parsedScore[1]?parsedScore[1]:0)/2;
  47. x.insertBefore(fromHTML(`<td style="white-space: nowrap">${value.toLocaleString()}</td>`),x.children[2]);
  48. }
  49. document.body.style['maxWidth']='950px';
  50. })();