Web Performance Enhancer - Firefox & Firefox Forks

Quicklink Enabling for Firefox & Firefox Forks

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

QingJ © 2025

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