Greasy Fork 还支持 简体中文。

WAX CPU Usage Indicator

Show WAX CPU percentage used in top left corner

目前為 2022-03-02 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name WAX CPU Usage Indicator
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Show WAX CPU percentage used in top left corner
  6. // @author Xortrox
  7. // @esversion: 6
  8. // @match https://play.arenaofglory.io/*
  9. // @icon https://play.arenaofglory.io/favicon.ico
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (async function() {
  14. 'use strict';
  15.  
  16. const walletAddressKey = 'user-script-wallet-address';
  17. let walletAddress = localStorage.getItem(walletAddressKey) || undefined;
  18.  
  19. const cpuDivId = 'user-script-cpu';
  20. const walletInputId = 'user-script-wallet-address';
  21. const walletSaveButtonId = 'user-script-wallet-save';
  22.  
  23. const cpuUpdateIntervalMS = 10000;
  24.  
  25. async function getWaxAccount(accountName) {
  26. return (await fetch('https://chain.wax.io/v1/chain/get_account', { method: 'POST', body: JSON.stringify({account_name: accountName}) })).json();
  27. }
  28.  
  29. async function getWaxCPUPercentage(accountName) {
  30. const account = await getWaxAccount(accountName);
  31.  
  32. return (account.cpu_limit.used / account.cpu_limit.max * 100).toFixed(2);
  33. }
  34.  
  35. function touchCPUDiv() {
  36. const exists = document.getElementById(cpuDivId);
  37.  
  38. if (!exists) {
  39. const div = document.createElement('div');
  40. div.id = cpuDivId;
  41. div.setAttribute('style', 'position: fixed; left: 5px; top: 5px; height: 25px; background: rgba(1,1,1,0.7); border: 1px solid limegreen; color: limegreen; padding: 3px; cursor: pointer;');
  42.  
  43. const walletSaveButton = document.createElement('button');
  44. walletSaveButton.id = walletSaveButtonId;
  45. walletSaveButton.setAttribute('style', 'background: transparent; color: limegreen; height: 25px; cursor: pointer;');
  46. walletSaveButton.innerText = 'Save';
  47. walletSaveButton.addEventListener('click', () => {
  48. const walletInput = document.getElementById(walletInputId);
  49. localStorage.setItem(walletAddressKey, walletInput.value);
  50. walletAddress = localStorage.getItem(walletAddressKey) || undefined;
  51. updateCPUPercentage();
  52. });
  53.  
  54. const walletInput = document.createElement('input');
  55. walletInput.id = walletInputId;
  56. walletInput.setAttribute('style', 'width: 100px; background: transparent; color: limegreen; height: 25px;');
  57. walletInput.setAttribute('data-lpignore', 'true');
  58. walletInput.setAttribute('type', 'text');
  59. walletInput.setAttribute('name', 'user-script-wallet');
  60. walletInput.setAttribute('placeholder', 'Wallet Address');
  61. walletInput.addEventListener('input', () => {
  62. console.log('input', walletInput.value);
  63. });
  64. walletInput.addEventListener('blur', () => {
  65. console.log('blur', walletInput.value);
  66. });
  67.  
  68. div.appendChild(walletSaveButton);
  69.  
  70. div.appendChild(walletInput);
  71.  
  72. const cpuSpan = document.createElement('span');
  73. cpuSpan.id = cpuDivId + '-span';
  74. cpuSpan.setAttribute('style', 'padding: 3px;');
  75.  
  76. div.appendChild(cpuSpan);
  77.  
  78. div.addEventListener('click', () => {
  79. updateCPUPercentage();
  80. });
  81.  
  82. document.body.appendChild(div);
  83. }
  84.  
  85. return document.getElementById(cpuDivId + '-span');
  86. }
  87.  
  88. async function updateCPUPercentage() {
  89. const div = touchCPUDiv();
  90.  
  91. if (walletAddress) {
  92. div.innerText = `CPU usage: ${await getWaxCPUPercentage(walletAddress)}%`;
  93. }
  94. }
  95.  
  96. updateCPUPercentage();
  97.  
  98. setInterval(updateCPUPercentage, cpuUpdateIntervalMS);
  99. })();