Greasy Fork镜像 支持简体中文。

网页加载分析

测试网页加载速度并显示加载最慢的三个网址的域名。Test the webpage loading speed and display the domain names of the three slowest loading URLs.

  1. // ==UserScript==
  2. // @name 网页加载分析
  3. // @version 1.07
  4. // @description 测试网页加载速度并显示加载最慢的三个网址的域名。Test the webpage loading speed and display the domain names of the three slowest loading URLs.
  5. // @match *://*/*
  6. // @run-at document-start
  7. // @author yzcjd
  8. // @author2 Lama AI 辅助
  9. // @namespace https://gf.qytechs.cn/users/1171320
  10. // @exclude *://*.cloudflare.com/*
  11. // @exclude *://*.recaptcha.net/*
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. const loadTimeElement = document.createElement('div');
  19. loadTimeElement.id = 'loadTimeDisplay';
  20. loadTimeElement.style.cssText = `
  21. position: fixed;
  22. top: 90%;
  23. left: 50%;
  24. transform: translate(-50%, -50%);
  25. background: grey;
  26. padding: 5px;
  27. border-radius: 8px;
  28. box-shadow: 0 0 15px rgba(0,0,0,0.3);
  29. white-space: nowrap;
  30. width: 400px;
  31. z-index: 9999;
  32. background-color: #f5f5f5;
  33. color: black;
  34. `;
  35.  
  36. const startTime = performance.now();
  37. let slowestRequests = [];
  38.  
  39. const networkObserver = new PerformanceObserver((list, observer) => {
  40. const entries = list.getEntries();
  41. entries.forEach(entry => {
  42. slowestRequests.push({ name: entry.name, duration: entry.duration });
  43. slowestRequests.sort((a, b) => b.duration - a.duration);
  44. slowestRequests = slowestRequests.slice(0, 3);
  45. });
  46. });
  47.  
  48. networkObserver.observe({ entryTypes: ['resource'] });
  49.  
  50. window.addEventListener('load', () => {
  51. const endTime = performance.now();
  52. const timeElapsed = endTime - startTime;
  53.  
  54. let networkInfo = '';
  55. if (slowestRequests.length > 0) {
  56. networkInfo = slowestRequests.map(req => {
  57. try {
  58. const url = new URL(req.name);
  59. return `slow: ${url.hostname} (${req.duration.toFixed(2)}ms)<br>`;
  60. } catch (error) {
  61. return `slow: Invalid URL (${req.duration.toFixed(2)}ms)<br>`;
  62. }
  63. }).join('');
  64. } else {
  65. networkInfo = '[none]';
  66. }
  67.  
  68. loadTimeElement.innerHTML = `
  69. <h2>Time: ${timeElapsed.toFixed(2)}ms</h2>
  70. ${networkInfo}
  71. `;
  72.  
  73. document.body.appendChild(loadTimeElement);
  74.  
  75. setTimeout(() => {
  76. loadTimeElement.remove();
  77. }, 5000);
  78. });
  79. })();

QingJ © 2025

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