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

better FPS unlocker and counter

目前為 2024-05-12 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
})();