Miniblox FPS Display

Affiche le nombre de FPS en haut à gauche de l'écran

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Miniblox FPS Display
// @namespace    https://github.com/AdrienPlaza
// @version      1.0
// @description  Affiche le nombre de FPS en haut à gauche de l'écran
// @author       PrimeFR
// @match        https://miniblox.io/*
// @icon         https://miniblox.io/favicon.png
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const fpsDisplay = document.createElement('div');
    fpsDisplay.style.position = 'fixed';
    fpsDisplay.style.top = '10px';
    fpsDisplay.style.right = '10px';
    fpsDisplay.style.backgroundColor = 'purple';
    fpsDisplay.style.color = 'white';
    fpsDisplay.style.border = '2px solid black';
    fpsDisplay.style.padding = '5px';
    fpsDisplay.style.zIndex = '1000';
    fpsDisplay.style.fontFamily = 'Arial, sans-serif';
    fpsDisplay.style.fontSize = '14px';
    document.body.appendChild(fpsDisplay);

    let lastTimestamp = performance.now();
    let frames = 0;

    function updateFPS() {
        const now = performance.now();
        frames++;

        if (now - lastTimestamp >= 1000) {
            const fps = frames;
            fpsDisplay.textContent = `FPS: ${fps}`;
            frames = 0;
            lastTimestamp = now;
        }

        requestAnimationFrame(updateFPS);
    }

    updateFPS();
})();