Greasy Fork 支持简体中文。

PPS Counter

Displays pixels per second

目前為 2025-04-14 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name PPS Counter
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Displays pixels per second
  6. // @author guildedbird
  7. // @match pixelplace.io/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. const counterUI = document.createElement('div');
  16. counterUI.style.position = 'absolute';
  17. counterUI.style.top = '35px';
  18. counterUI.style.right = '135px';
  19. counterUI.style.padding = '4px 6px';
  20. counterUI.style.background = 'rgba(0, 0, 0, 0.45)';
  21. counterUI.style.color = '#FFFFFF';
  22. counterUI.style.fontFamily = 'Arial';
  23. counterUI.style.fontSize = '0.7em';
  24. counterUI.style.zIndex = '10';
  25. counterUI.style.borderRadius = '34px';
  26. counterUI.style.pointerEvents = 'none';
  27. counterUI.style.display = 'none';
  28. document.body.appendChild(counterUI);
  29.  
  30. let messagesInCurrentSecond = 0;
  31. let maxMessagesPerSecond = 0;
  32. let lastTimestamp = Math.floor(Date.now() / 1000);
  33. const SEND_CAP = 55.555;
  34. let lastSendTimestamp = Date.now();
  35.  
  36. setInterval(() => {
  37. const currentTime = Date.now();
  38. if (currentTime - lastSendTimestamp >= 3000) {
  39. maxMessagesPerSecond = 0;
  40. counterUI.textContent = `PPS: ${maxMessagesPerSecond}`;
  41. counterUI.style.display = 'none';
  42. console.log('[Tampermonkey] Sec Max reset and UI hidden after 3 seconds of inactivity.');
  43. }
  44. }, 1000);
  45.  
  46. const hookEmit = () => {
  47. const io = window.io;
  48. if (!io || !io.Socket) {
  49. setTimeout(hookEmit, 500);
  50. return;
  51. }
  52.  
  53. const originalEmit = io.Socket.prototype.emit;
  54.  
  55. io.Socket.prototype.emit = function (...args) {
  56. const currentTimestamp = Math.floor(Date.now() / 1000);
  57.  
  58. if (currentTimestamp !== lastTimestamp) {
  59. maxMessagesPerSecond -= messagesInCurrentSecond;
  60. if (maxMessagesPerSecond < 0) {
  61. maxMessagesPerSecond = 0;
  62. }
  63.  
  64. maxMessagesPerSecond = Math.max(maxMessagesPerSecond, messagesInCurrentSecond);
  65. lastTimestamp = currentTimestamp;
  66. messagesInCurrentSecond = 0;
  67. }
  68.  
  69. if (messagesInCurrentSecond < SEND_CAP) {
  70. messagesInCurrentSecond++;
  71. lastSendTimestamp = Date.now();
  72. counterUI.textContent = `PPS: ${maxMessagesPerSecond}`;
  73. counterUI.style.display = 'block';
  74. return originalEmit.apply(this, args);
  75. } else {
  76. console.log('[Tampermonkey] Send cap reached for this second.');
  77. return false;
  78. }
  79. };
  80.  
  81. console.log('[Tampermonkey] Hooked into Socket.IO emit() with cap');
  82. };
  83.  
  84. hookEmit();
  85. })();