Hardware Acceleration and Web Performance Enhancer

Toggle hardware acceleration and enhance web performance without logging users out

目前為 2024-09-11 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Hardware Acceleration and Web Performance Enhancer
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Toggle hardware acceleration and enhance web performance without logging users out
  6. // @author Tae
  7. // @match *://*/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Load Quicklink
  16. const script = document.createElement('script');
  17. script.src = 'https://unpkg.com/quicklink@2.0.0/dist/quicklink.umd.js';
  18. script.onload = () => {
  19. try {
  20. quicklink.listen({
  21. origins: true, // Only prefetch links from the same origin
  22. ignores: [ // Ignore links that might cause issues
  23. (uri) => uri.includes('logout'),
  24. (uri) => uri.includes('login'),
  25. (uri) => uri.includes('account')
  26. ]
  27. });
  28. } catch (error) {
  29. console.error('Error loading Quicklink:', error);
  30. }
  31. };
  32. document.head.appendChild(script);
  33.  
  34. // Additional error handling
  35. window.addEventListener('error', (event) => {
  36. console.error('Script error:', event.message);
  37. });
  38.  
  39. // Prevent logging out users
  40. document.addEventListener('click', (event) => {
  41. const target = event.target;
  42. if (target.tagName === 'A' && (target.href.includes('logout') || target.href.includes('login') || target.href.includes('account'))) {
  43. event.preventDefault();
  44. console.warn('Prevented navigation to:', target.href);
  45. }
  46. });
  47.  
  48. // Prevent 503 errors and other page down errors
  49. window.addEventListener('beforeunload', (event) => {
  50. if (navigator.sendBeacon) {
  51. navigator.sendBeacon('/keep-alive', '');
  52. } else {
  53. const xhr = new XMLHttpRequest();
  54. xhr.open('POST', '/keep-alive', false);
  55. xhr.send('');
  56. }
  57. });
  58.  
  59. // Monitor for changes in the URL to prevent logging out
  60. let lastUrl = location.href;
  61. new MutationObserver(() => {
  62. const url = location.href;
  63. if (url !== lastUrl) {
  64. lastUrl = url;
  65. if (url.includes('logout') || url.includes('login') || url.includes('account')) {
  66. history.replaceState(null, '', '/');
  67. console.warn('Prevented navigation to:', url);
  68. }
  69. }
  70. }).observe(document, { subtree: true, childList: true });
  71.  
  72. // Keep-alive mechanism to prevent 503 errors
  73. setInterval(() => {
  74. if (navigator.sendBeacon) {
  75. navigator.sendBeacon('/keep-alive', '');
  76. } else {
  77. const xhr = new XMLHttpRequest();
  78. xhr.open('POST', '/keep-alive', true);
  79. xhr.send('');
  80. }
  81. }, 300000); // Send keep-alive request every 5 minutes
  82. })();