Greasy Fork

Greasy Fork is available in English.

FPS显示

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);

})();