FPS显示

FPS显示是一个用户脚本,旨在为移动端设备提供实时的帧率 (FPS) 显示。该脚本在页面的固定位置创建一个半透明的显示框,实时更新并展示当前页面的帧率信息。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         FPS显示
// @namespace    http://tampermonkey.net/
// @version      0.1.5
// @description  FPS显示是一个用户脚本,旨在为移动端设备提供实时的帧率 (FPS) 显示。该脚本在页面的固定位置创建一个半透明的显示框,实时更新并展示当前页面的帧率信息。
// @license      MIT
// @author       zzzwq
// @match        http://*/*
// @match        https://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var bzyfps = document.createElement("div");
    bzyfps.id = "fps";
    bzyfps.style.cssText =
        "text-align:center !important;font-size:15px;width:70px;height:28px;line-height:28px;text-align:center;float:right;position:fixed;right:10px;top:10px;color:#9370DB;background:transparent;cursor:pointer;z-index:999999999;box-shadow:0px 0px 10px #888;border-radius:10%;user-select:none;pointer-events:none";
    document.body.appendChild(bzyfps);

    var showFPS = (function() {
        var frames = 0;
        var lastTime = performance.now();
        var lastFps = 0;
        var requestId;

        function updateFPS() {
            var currentTime = performance.now();
            var delta = currentTime - lastTime;
            if (delta >= 1000) {
                var fps = Math.round((frames * 1000) / delta);
                if (fps !== lastFps) {
                    bzyfps.textContent = "FPS: " + fps;
                    lastFps = fps;
                }
                lastTime = currentTime;
                frames = 0;
            }
            frames++;
            requestId = requestAnimationFrame(updateFPS);
        }

        function start() {
            requestId = requestAnimationFrame(updateFPS);
        }

        function stop() {
            cancelAnimationFrame(requestId);
        }

        return {
            start: start,
            stop: stop
        };
    })();

    showFPS.start();

    // 监听滚动事件,当用户停止滚动时,可以减少FPS的更新频率
    var isScrolling;
    window.addEventListener('scroll', function(event) {
        window.clearTimeout(isScrolling);
        isScrolling = setTimeout(function() {
            // 用户停止滚动后的操作
        }, 100);
    }, false);

})();