FPS and Ping Counter(for optimize click two on "optimize in menu"

better FPS unlocker and counter

当前为 2024-05-12 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         FPS and Ping Counter(for optimize click two on "optimize in menu"
// @namespace    http://tampermonkey.net/
// @version      3.2
// @description  better FPS unlocker and counter
// @author       kyu
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
'use strict';
var fpsCounter = document.createElement('div');
fpsCounter.style.position = 'fixed';
fpsCounter.style.top = '0px';
fpsCounter.style.left = '0px';
fpsCounter.style.backgroundColor = 'rgba(255, 128, 0, 0.5)';
fpsCounter.style.color = 'white';
fpsCounter.style.padding = '5px';
fpsCounter.style.fontSize = '12px';
fpsCounter.style.borderRadius = '5px';
fpsCounter.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.5)';
fpsCounter.textContent = 'FPS: 0';

var pingCounter = document.createElement('div');
pingCounter.style.position = 'fixed';
pingCounter.style.top = '20px';
pingCounter.style.left = '0px';
pingCounter.style.backgroundColor = 'rgba(0, 128, 255, 0.5)';
pingCounter.style.color = 'white';
pingCounter.style.padding = '5px';
pingCounter.style.fontSize = '12px';
pingCounter.style.borderRadius = '5px';
pingCounter.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.5)';
pingCounter.textContent = 'Ping: 0ms';

document.body.appendChild(fpsCounter);
document.body.appendChild(pingCounter);

var menuButton = document.createElement('button');
menuButton.style.position = 'fixed';
menuButton.style.top = '0px';
menuButton.style.right = '0px';
menuButton.style.backgroundColor = 'rgba(255, 255, 255, 0.5)';
menuButton.style.color = 'black';
menuButton.style.padding = '5px';
menuButton.style.fontSize = '12px';
menuButton.style.borderRadius = '5px';
menuButton.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.5)';
menuButton.textContent = 'Menu';

document.body.appendChild(menuButton);

var menu = document.createElement('div');
menu.style.position = 'fixed';
menu.style.top = '50%';
menu.style.left = '50%';
menu.style.transform = 'translate(-50%, -50%)';menu.style.backgroundColor = 'rgba(255, 255, 255, 0.5)';
menu.style.color = 'black';
menu.style.padding = '10px';
menu.style.fontSize = '12px';
menu.style.borderRadius = '5px';
menu.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.5)';
menu.style.display = 'none';

var checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.checked = true;
menu.appendChild(checkbox);

var label = document.createElement('label');
label.textContent = 'Enable counters';
menu.appendChild(label);

var optimizationCheckbox = document.createElement('input');
optimizationCheckbox.type = 'checkbox';
optimizationCheckbox.checked = true;
menu.appendChild(optimizationCheckbox);

var optimizationLabel = document.createElement('label');
optimizationLabel.textContent = 'Optimize';
menu.appendChild(optimizationLabel);

menuButton.addEventListener('click', function() {
if (menu.style.display === 'none') {
menu.style.display = 'block';
} else {
menu.style.display = 'none';
}
});

checkbox.addEventListener('change', function() {
if (checkbox.checked) {
fpsCounter.style.display = 'block';
pingCounter.style.display = 'block';
} else {
fpsCounter.style.display = 'none';
pingCounter.style.display = 'none';
}
});

optimizationCheckbox.addEventListener('change', function() {
if (optimizationCheckbox.checked) {
// Optimize page
var images = document.querySelectorAll('img');
for (var i = 0; i < images.length; i++) {
images[i].src = '';
}
var scripts = document.querySelectorAll('script');
for (var i = 0; i < scripts.length; i++) {
scripts[i].remove();
}
} else {
// Deoptimize page
//...
}
});

// Make counters draggable
fpsCounter.addEventListener('mousedown', function(event) {
fpsCounter.style.position = 'absolute';
fpsCounter.style.zIndex = '1000';
document.addEventListener('mousemove', function(event) {
fpsCounter.style.top = event.clientY + 'px';
fpsCounter.style.left = event.clientX + 'px';
});
document.addEventListener('mouseup', function() {
fpsCounter.style.position = 'fixed';
});
});

pingCounter.addEventListener('mousedown', function(event) {
pingCounter.style.position = 'absolute';
pingCounter.style.zIndex = '1000';
document.addEventListener('mousemove', function(event) {
pingCounter.style.top = event.clientY + 'px';
pingCounter.style.left = event.clientX + 'px';
});
document.addEventListener('mouseup', function() {
pingCounter.style.position = 'fixed';
});
});

// Bypass to always appear on any page
document.addEventListener('DOMContentLoaded', function() {
if (document.body.style.overflow!== 'hidden') {
document.body.style.overflow = 'hidden';
}
});

// Update FPS and ping counters
var fps = 0;
var ping = 0;
var lastFrameTime = performance.now();

function updateFPS() {
var currentFrameTime = performance.now();
fps = Math.round(1000 / (currentFrameTime - lastFrameTime));
lastFrameTime = currentFrameTime;
fpsCounter.textContent = 'FPS: ' + fps;
}

function updatePing() {
var startTime = performance.now();
var xhr = new XMLHttpRequest();
xhr.open('GET', location.href, true);
xhr.onload = function() {
ping = Math.round(performance.now() - startTime);
pingCounter.textContent = 'Ping: ' + ping + 'ms';
};
xhr.send();
}

setInterval(updateFPS, 1000 / 60); // update FPS every 16ms (60fps)
setInterval(updatePing, 1000); // update ping every 1s

document.body.appendChild(menu);
})();