FPS Counter and Site Optimization

Display FPS counter and optimize site performance

目前為 2024-02-06 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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;
    };
})();