FPS显示

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

  1. // ==UserScript==
  2. // @name FPS显示
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.5
  5. // @description FPS显示是一个用户脚本,旨在为移动端设备提供实时的帧率 (FPS) 显示。该脚本在页面的固定位置创建一个半透明的显示框,实时更新并展示当前页面的帧率信息。
  6. // @license MIT
  7. // @author zzzwq
  8. // @match http://*/*
  9. // @match https://*/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. var bzyfps = document.createElement("div");
  17. bzyfps.id = "fps";
  18. bzyfps.style.cssText =
  19. "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";
  20. document.body.appendChild(bzyfps);
  21.  
  22. var showFPS = (function() {
  23. var frames = 0;
  24. var lastTime = performance.now();
  25. var lastFps = 0;
  26. var requestId;
  27.  
  28. function updateFPS() {
  29. var currentTime = performance.now();
  30. var delta = currentTime - lastTime;
  31. if (delta >= 1000) {
  32. var fps = Math.round((frames * 1000) / delta);
  33. if (fps !== lastFps) {
  34. bzyfps.textContent = "FPS: " + fps;
  35. lastFps = fps;
  36. }
  37. lastTime = currentTime;
  38. frames = 0;
  39. }
  40. frames++;
  41. requestId = requestAnimationFrame(updateFPS);
  42. }
  43.  
  44. function start() {
  45. requestId = requestAnimationFrame(updateFPS);
  46. }
  47.  
  48. function stop() {
  49. cancelAnimationFrame(requestId);
  50. }
  51.  
  52. return {
  53. start: start,
  54. stop: stop
  55. };
  56. })();
  57.  
  58. showFPS.start();
  59.  
  60. // 监听滚动事件,当用户停止滚动时,可以减少FPS的更新频率
  61. var isScrolling;
  62. window.addEventListener('scroll', function(event) {
  63. window.clearTimeout(isScrolling);
  64. isScrolling = setTimeout(function() {
  65. // 用户停止滚动后的操作
  66. }, 100);
  67. }, false);
  68.  
  69. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址