网页加载速度测试

测试网页加载速度

  1. // ==UserScript==
  2. // @name 网页加载速度测试
  3. // @author ChatGPT
  4. // @version 3.1.4
  5. // @description 测试网页加载速度
  6. // @match *://*/*
  7. // @run-at document-start
  8. // @grant none
  9. // @namespace https://gf.qytechs.cn/users/452911
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. // 创建显示元素
  14. const loadTimeElement = document.createElement('div');
  15. // 白色背景黑色文字的简洁样式,确保居中
  16. loadTimeElement.style.cssText = `
  17. position: fixed;
  18. top: 50%;
  19. left: 50%;
  20. transform: translate(-50%, -50%);
  21. background: rgba(255, 255, 255, 0.98);
  22. padding: 12px 24px;
  23. border-radius: 8px;
  24. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
  25. color: #222;
  26. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  27. font-size: 15px;
  28. font-weight: 500;
  29. line-height: 1.5;
  30. text-align: center;
  31. z-index: 999999;
  32. border: 1px solid rgba(0, 0, 0, 0.1);
  33. transition: all 0.3s ease;
  34. max-width: 90vw;
  35. box-sizing: border-box;
  36. display: inline-flex;
  37. align-items: center;
  38. justify-content: center;
  39. white-space: nowrap;
  40. `;
  41.  
  42. // 添加动画效果
  43. const style = document.createElement('style');
  44. style.textContent = `
  45. @keyframes fadeInScale {
  46. 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
  47. 100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  48. }
  49. @keyframes fadeOutScale {
  50. 0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  51. 100% { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
  52. }
  53. `;
  54. document.head.appendChild(style);
  55.  
  56. const startTime = performance.now();
  57.  
  58. window.addEventListener('load', () => {
  59. const endTime = performance.now();
  60. const timeElapsed = endTime - startTime;
  61. loadTimeElement.textContent = `页面加载耗时: ${timeElapsed.toFixed(2)} 毫秒`;
  62. // 添加淡入动画
  63. loadTimeElement.style.animation = 'fadeInScale 0.25s cubic-bezier(0.2, 0, 0, 1.2) forwards';
  64. document.body.appendChild(loadTimeElement);
  65. // 淡出消失
  66. setTimeout(() => {
  67. loadTimeElement.style.animation = 'fadeOutScale 0.25s ease forwards';
  68. setTimeout(() => {
  69. loadTimeElement.remove();
  70. }, 50);
  71. }, 1500);
  72. });
  73. })();

QingJ © 2025

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