Display FPS counter and optimize site performance
目前為
// ==UserScript==
// @name FPS Counter and Site Optimization
// @namespace http://tampermonkey.net/
// @version 0.5
// @description Display FPS counter and optimize site performance
// @author Kyu
// @match *://*/*
// @license MIT License
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Display optimization message
const messageElement = document.createElement('div');
messageElement.id = 'optimizationMessage';
document.body.insertBefore(messageElement, document.body.firstChild);
messageElement.textContent = 'Optimizing site...';
setTimeout(() => {
messageElement.textContent = 'Optimization completed';
setTimeout(() => {
messageElement.remove();
}, 1000);
}, 3000);
// Measure FPS
const fpsElement = document.createElement('div');
fpsElement.id = 'fpsCounter';
document.body.insertBefore(fpsElement, document.body.firstChild);
const fpsMeasurement = function() {
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);
};
let frame = window.performance.now();
requestAnimationFrame(fpsMeasurement);
// Optimize site performance
const originalCreateObjectURL = window.URL.createObjectURL;
window.URL.createObjectURL = function(blob) {
const revokeObjectURL = originalCreateObjectURL.apply(this, arguments);
setTimeout(() => {
revokeObjectURL.apply(this, arguments);
}, 10000); // Revoke after 10 seconds
return revokeObjectURL;
};
const originalImageOnLoad = Image.prototype.onload;
Image.prototype.onload = function() {
const originalImage = originalImageOnLoad.apply(this, arguments);
this.onload = originalImageOnLoad;
};
})();