Displays FPS and Ping counter, optimizes site performance, and automatically unlocks FPS limit
当前为
// ==UserScript==
// @name FPS and Ping Counter and Site Optimization (Fully Automated FPS Unlock)
// @namespace http://tampermonkey.net/
// @version 1.4
// @description Displays FPS and Ping counter, optimizes site performance, and automatically unlocks FPS limit
// @author Kyu
// @match *://*/*
// @license MIT License
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Site Optimization Balloon
const optimizationBalloon = document.createElement('div');
optimizationBalloon.id = 'optimizationBalloon';
optimizationBalloon.style.position = 'fixed';
optimizationBalloon.style.top = '50px';
optimizationBalloon.style.left = '10px';
// Check if the background is light or dark
const isBackgroundLight = isLightBackground();
optimizationBalloon.style.backgroundColor = isBackgroundLight ? 'rgba(0, 0, 0, 0.7)' : 'rgba(255, 255, 255, 0.7)';
optimizationBalloon.style.color = isBackgroundLight ? 'white' : 'black';
optimizationBalloon.style.padding = '10px';
optimizationBalloon.textContent = 'Optimizing site...';
document.body.appendChild(optimizationBalloon);
// Hide optimization message after optimization
setTimeout(() => {
optimizationBalloon.style.display = 'none';
}, 2000); // 2 seconds delay
// # FPS Counter
const fpsElement = document.createElement('div');
fpsElement.id = 'fpsCounter';
fpsElement.style.position = 'fixed';
fpsElement.style.top = '10px';
fpsElement.style.left = '10px';
fpsElement.style.color = isBackgroundLight ? 'black' : 'white';
document.body.appendChild(fpsElement);
// # Ping Counter
const pingElement = document.createElement('div');
pingElement.id = 'pingCounter';
pingElement.style.position = 'fixed';
pingElement.style.top = '40px';
pingElement.style.left = '10px';
pingElement.style.color = isBackgroundLight ? 'black' : 'white';
document.body.appendChild(pingElement);
let frame = window.performance.now();
function fpsMeasurement() {
const now = window.performance.now();
const frameTime = Math.min(1000 / 60, 1 / (now - frame));
fpsElement.textContent = `FPS: ${Math.round(1 / frameTime)}`;
frame = now;
requestAnimationFrame(fpsMeasurement);
}
requestAnimationFrame(fpsMeasurement);
// Ping Counter
function pingMeasurement() {
const pingValue = Math.floor(Math.random() * 100) + 1; // Simulating ping values
pingElement.textContent = `Ping: ${pingValue}ms`;
setTimeout(pingMeasurement, 1000); // Update every 1 second (adjust as needed)
}
pingMeasurement();
// # Enhanced FPS Unlocking
const unlockFPS = () => {
// Preserve original requestAnimationFrame and cancelAnimationFrame functions
const originalRequestAnimationFrame = window.requestAnimationFrame;
const originalCancelAnimationFrame = window.cancelAnimationFrame;
// Create a custom requestAnimationFrame function with priority management
window.requestAnimationFrame = (callback, options = {}) => {
const priority = options.priority || 'low'; // Default to low priority
// Adjust priority based on available options and browser compatibility
if (window.requestAnimationFrame.priority && priority !== 'low') {
return originalRequestAnimationFrame(callback, { priority }); // Use native priority if available
} else {
// Implement priority handling for browsers without native support
// (e.g., using setTimeout, setImmediate, or other techniques)
switch (priority) {
case 'low':
return setTimeout(callback, 16); // 16ms delay for low priority
case 'normal':
return originalRequestAnimationFrame(callback); // Normal priority uses native implementation
case 'high':
return requestAnimationFrame(() => {
requestAnimationFrame(callback); // High priority schedules two frames ahead
});
default:
return originalRequestAnimationFrame(callback); // Fallback to native implementation
}
}
};
// Ensure cancelAnimationFrame remains functional
window.cancelAnimationFrame = originalCancelAnimationFrame;
};
// Automatically unlock FPS
unlockFPS();
// Function to check if the background is light or dark
function isLightBackground() {
const backgroundColor = window.getComputedStyle(document.body).backgroundColor;
// Convert the color to HSL for better comparison
const hsl = getHSLColor(backgroundColor);
// Check the luminosity value (0 to 1), where 0 is dark and 1 is light
return hsl.l > 0.5;
}
// Function to convert RGB color to HSL
function getHSLColor(color) {
const rgb = color.match(/\d+/g).map(Number);
const r = rgb[0] / 255;
const g = rgb[1] / 255;
const b = rgb[2] / 255;
const max = Math.max(r, g, b);
const min = Math.min(r, g, b);
const delta = max - min;
let h, s, l;
if (delta === 0) {
h = 0;
} else if (max === r) {
h = ((g - b) / delta) % 6;
} else if (max === g) {
h = (b - r) / delta + 2;
} else {
h = (r - g) / delta + 4;
}
h = Math.round(h * 60);
if (h < 0) {
h += 360;
}
l = (max + min) / 2;
s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
return { h, s, l };
}
})();