Hardware Acceleration and Web Performance Enhancer

Toggle hardware acceleration and enhance web performance without logging users out

  1. // ==UserScript==
  2. // @name Hardware Acceleration and Web Performance Enhancer
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.4
  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 library to enhance link prefetching
  16. const script = document.createElement('script');
  17. script.src = 'https://unpkg.com/quicklink@2.0.0/dist/quicklink.umd.js';
  18. script.onload = () => {
  19. if (typeof quicklink !== 'undefined') {
  20. try {
  21. quicklink.listen({
  22. origins: true,
  23. ignores: [
  24. (uri) => uri.includes('logout'),
  25. (uri) => uri.includes('login'),
  26. (uri) => uri.includes('account')
  27. ]
  28. });
  29. } catch (error) {
  30. console.error('Error initializing Quicklink:', error);
  31. }
  32. } else {
  33. console.error('Quicklink library is not available.');
  34. }
  35. };
  36. script.onerror = () => {
  37. console.error('Error loading Quicklink library.');
  38. };
  39. document.head.appendChild(script);
  40.  
  41. // Global error listener
  42. window.addEventListener('error', (event) => {
  43. console.error('Script error:', event.message, 'at', event.filename, 'line', event.lineno);
  44. });
  45.  
  46. // Prevent navigation to logout, login, or account pages on link clicks
  47. document.addEventListener('click', (event) => {
  48. const target = event.target.closest('a[href]');
  49. if (target && (target.href.includes('logout') || target.href.includes('login') || target.href.includes('account'))) {
  50. event.preventDefault();
  51. console.warn('Prevented navigation to:', target.href);
  52. }
  53. });
  54.  
  55. // Prevent 503 errors by sending keep-alive requests
  56. const sendKeepAlive = () => {
  57. const url = '/keep-alive';
  58. if (navigator.sendBeacon) {
  59. try {
  60. navigator.sendBeacon(url, '');
  61. } catch (error) {
  62. console.error('Error sending beacon:', error);
  63. }
  64. } else {
  65. const xhr = new XMLHttpRequest();
  66. xhr.open('POST', url, true);
  67. xhr.onerror = () => {
  68. console.error('Error with keep-alive request:', xhr.statusText);
  69. };
  70. xhr.send('');
  71. }
  72. };
  73. setInterval(sendKeepAlive, 300000); // Send keep-alive request every 5 minutes
  74.  
  75. })();