// ==UserScript== // @name Web Page Accelerator // @namespace instant.page // @version v1.0.5.2.0 // @author OB_BUFF // @description Automatically accelerates hyperlinks on web pages to improve loading speed. Integrates the latest instant.page v5.2.0 features with multi-language support (default: English) and removes store link redirection functionality. // @license GPL-v3 // @require https://registry.npmmirror.com/sweetalert2/10.16.6/files/dist/sweetalert2.min.js // @resource swalStyle https://registry.npmmirror.com/sweetalert2/10.16.6/files/dist/sweetalert2.min.css // @match *://*/* // @noframes // @run-at document-idle // @grant GM_openInTab // @grant GM_setValue // @grant GM_getValue // @grant GM_registerMenuCommand // @grant GM_getResourceText // @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMjggMTI4Ij48cGF0aCBkPSJNMCA3OWMwLTM1LjQgMjguNS02NCA2My45LTY0LjFzNjQuMSAyOC42IDY0LjEgNjRjMCA5LjQtMi4xIDE4LjQtNS43IDI2LjUtMSAyLjMtMi4zIDQuNi0zLjYgNi43LS40LjYtMSAxLTEuNyAxSDExYy0uNyAwLTEuMy0uNC0xLjctMS0xLjMtMi4yLTIuNS00LjQtMy42LTYuN0MyLjEgOTcuNCAwIDg4LjQgMCA3OXptMjQuNC0zOS43Yy01LjIgNS4xLTkuMiAxMS4xLTEyIDE3LjgtMyA2LjktNC41IDE0LjItNC41IDIxLjhhNTUuODYgNTUuODYgMCAwIDAgNC40IDIxLjhjLjcgMS42IDEuNCAzLjIgMi4yIDQuN2g5OC44Yy44LTEuNSAxLjYtMy4xIDIuMi00LjdhNTUuODYgNTUuODYgMCAwIDAgNC40LTIxLjggNTUuODYgNTUuODYgMCAwIDAtNC40LTIxLjhjLTIuOC02LjctNi45LTEyLjctMTItMTcuOC01LjEtNS4yLTExLjEtOS4yLTE3LjgtMTJhNTUuODYgNTUuODYgMCAwIDAtMjEuOC00LjQgNTUuODYgNTUuODYgMCAwIDAtMjEuOCA0LjRjLTYuNiAyLjgtMTIuNiA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LjNBNDIuMDQgNDIuMDQgMCAwIDEgMjYgNjNjMi01IDUtOS40IDguOC0xMy4yUzQzIDQzLjEgNDcuOSA0MWE0Mi4wNCA0Mi4wNCAwIDAgMSAzMi4yIDBjNC45IDIuMSA5LjMgNS4xIDEzLjEgOC45Qzk3IDUzLjYgOTkuOSA1OCAxMDIgNjNhNDIuMDQgNDIuMDQgMCAwIDEgMy4yIDE2LjFjMCAzLjItLjQgNi4zLTEuMSA5LjMtLjYgMi41IDEuMyA0LjkgMy45IDQuOSAxLjggMCAzLjUtMS4zIDMuOS0zLjEuOC0zLjYgMS4zLTcuMyAxLjMtMTEuMSAwLTI3LjMtMjIuMS00OS4zLTQ5LjMtNDkuM3oiIGZpbGw9IiM0NDQiLz48L3N2Zz4= // @downloadURL https://update.greasyfork.icu/scripts/526323/Web%20Page%20Accelerator.user.js // @updateURL https://update.greasyfork.icu/scripts/526323/Web%20Page%20Accelerator.meta.js // ==/UserScript== /* ------------------------------- Multi-language support (default: English) You can extend the translations object to support more languages. ---------------------------------- */ const translations = { en: { acceleratedCount: "Accelerated: ", times: " times", resetPrompt: "Are you sure you want to reset the acceleration count?", confirm: "OK", cancel: "Cancel", settingsTitle: "Accelerator Settings", accelerateExternal: "Accelerate external links", accelerateParams: "Accelerate links with parameters", openInSameTab: "Open links in the same tab", animationEffect: "Animation effect", prefetchDelay: "Prefetch delay (ms)", excludeURLs: "Exclude the following URLs (one per line)", excludeKeywords: "Exclude the following keywords (one per line)", save: "Save", usageFooter: "Click here to view the usage instructions. This assistant is free and open-source." } }; const lang = 'en'; // Default language // ------------------------------- // Utility functions // ------------------------------- let util = { getValue(name) { return GM_getValue(name); }, setValue(name, value) { GM_setValue(name, value); }, // Check if the given string (after removing '-' and '_') contains any of the keywords (case-insensitive) include(str, arr) { str = str.replace(/[-_]/ig, ''); for (let i = 0, l = arr.length; i < l; i++) { let val = arr[i].trim(); if (val !== '' && str.toLowerCase().indexOf(val.toLowerCase()) > -1) { return true; } } return false; }, addStyle(id, tag, css) { tag = tag || 'style'; let doc = document, styleDom = doc.getElementById(id); if (styleDom) return; let style = doc.createElement(tag); style.rel = 'stylesheet'; style.id = id; tag === 'style' ? style.innerHTML = css : style.href = css; doc.head.appendChild(style); }, // Common regex patterns reg: { chrome: /^https?:\/\/chrome\.google\.com\/webstore\/.+?\/([a-z]{32})(?=[\/#?]|$)/, chromeNew: /^https?:\/\/chromewebstore\.google\.com\/.+?\/([a-z]{32})(?=[\/#?]|$)/, edge: /^https?:\/\/microsoftedge\.microsoft\.com\/addons\/.+?\/([a-z]{32})(?=[\/#?]|$)/, firefox: /^https?:\/\/(reviewers\.)?(addons\.mozilla\.org|addons(?:-dev)?\.allizom\.org)\/.*?(?:addon|review)\/([^/<>"'?#]+)/, microsoft: /^https?:\/\/(?:apps|www)\.microsoft\.com\/(?:store|p)\/.+?\/([a-zA-Z\d]{10,})(?=[\/#?]|$)/, } }; // ------------------------------- // Main logic // ------------------------------- let main = { // Initialize configuration values (store values using GM storage) initValue() { // Note: The "store link" redirection option has been removed. let value = [{ name: 'setting_success_times', value: 0 }, { name: 'allow_external_links', value: true }, { name: 'allow_query_links', value: true }, { name: 'enable_target_self', value: false }, { name: 'enable_animation', value: false }, { name: 'delay_on_hover', value: 65 }, { name: 'exclude_list', value: '' }, { name: 'exclude_keyword', value: 'login\nlogout\nregister\nsignin\nsignup\nsignout\npay\ncreate\nedit\ndownload\ndel\nreset\nsubmit\ndoubleclick\ngoogleads\nexit' }]; value.forEach((v) => { if (util.getValue(v.name) === undefined) { util.setValue(v.name, v.value); } }); }, // Register menu commands for the settings panel and reset function registerMenuCommand() { GM_registerMenuCommand( "🚀 " + translations[lang].acceleratedCount + util.getValue('setting_success_times') + translations[lang].times, () => { Swal.fire({ showCancelButton: true, title: translations[lang].resetPrompt, icon: 'warning', confirmButtonText: translations[lang].confirm, cancelButtonText: translations[lang].cancel, customClass: { popup: 'instant-popup', }, }).then((res) => { if (res.isConfirmed) { util.setValue('setting_success_times', 0); history.go(0); } }); } ); let dom = `
`; GM_registerMenuCommand(translations[lang].settingsTitle, () => { Swal.fire({ title: translations[lang].settingsTitle, html: dom, showCloseButton: true, confirmButtonText: translations[lang].save, footer: `
${translations[lang].usageFooter}
`, customClass: { popup: 'instant-popup', }, }).then((res) => { if (res.isConfirmed) { history.go(0); } }); document.getElementById('S-External').addEventListener('change', (e) => { util.setValue('allow_external_links', e.currentTarget.checked); }); document.getElementById('S-Query').addEventListener('change', (e) => { util.setValue('allow_query_links', e.currentTarget.checked); }); document.getElementById('S-Target').addEventListener('change', (e) => { util.setValue('enable_target_self', e.currentTarget.checked); }); document.getElementById('S-Animate').addEventListener('change', (e) => { util.setValue('enable_animation', e.currentTarget.checked); }); document.getElementById('S-Delay').addEventListener('change', (e) => { util.setValue('delay_on_hover', e.currentTarget.value); }); document.getElementById('S-Exclude').addEventListener('change', (e) => { util.setValue('exclude_list', e.currentTarget.value); }); document.getElementById('S-Exclude-Word').addEventListener('change', (e) => { util.setValue('exclude_keyword', e.currentTarget.value); }); }); }, // Check if the current host is in the exclude list inExcludeList() { let exclude = util.getValue('exclude_list').split('\n').map(s => s.trim()); let host = location.host; return exclude.includes(host); }, // ------------------------------- // Main prefetch logic integrating instant.page v5.2.0 features // ------------------------------- instantPage() { if (window.instantLoaded) return; window.instantLoaded = true; // Configuration options (some from GM storage, some from data attributes) const allowQueryString = ('instantAllowQueryString' in document.body.dataset) || util.getValue('allow_query_links'); const allowExternalLinks = ('instantAllowExternalLinks' in document.body.dataset) || util.getValue('allow_external_links'); const _useWhitelist = ('instantWhitelist' in document.body.dataset); const enableAnimation = util.getValue('enable_animation'); const enableTargetSelf = util.getValue('enable_target_self'); const excludeKeyword = util.getValue('exclude_keyword').split('\n'); let delayOnHover = parseInt(util.getValue('delay_on_hover')); // Internal variables similar to instant.page v5.2.0 let _chromiumMajorVersionInUserAgent = null; let _speculationRulesType = 'none'; let _delayOnHover = delayOnHover; // in milliseconds let _lastTouchstartEvent = null; let _mouseoverTimer = null; let _preloadedList = new Set(); // Browser support check: ensure is supported let supportChecksRelList = document.createElement('link').relList; if (!(supportChecksRelList && supportChecksRelList.supports && supportChecksRelList.supports('prefetch'))) { return; } const chromium100Check = ('throwIfAborted' in AbortSignal.prototype); // Chromium 100+ const firefox115AndSafari17_0Check = supportChecksRelList.supports('modulepreload'); // Firefox 115+, Safari 17.0+ const safari15_4AndFirefox116Check = (Intl.PluralRules && 'selectRange' in Intl.PluralRules.prototype); const firefox115AndSafari15_4Check = firefox115AndSafari17_0Check || safari15_4AndFirefox116Check; const isBrowserSupported = chromium100Check && firefox115AndSafari15_4Check; if (!isBrowserSupported) return; // If the page sets data-instantVaryAccept (e.g. Shopify), check Chromium version if (document.body.dataset.instantVaryAccept) { const chromiumUserAgentIndex = navigator.userAgent.indexOf('Chrome/'); if (chromiumUserAgentIndex > -1) { _chromiumMajorVersionInUserAgent = parseInt(navigator.userAgent.substring(chromiumUserAgentIndex + 'Chrome/'.length)); } if (_chromiumMajorVersionInUserAgent && _chromiumMajorVersionInUserAgent < 110) { return; } } // Set speculation rules if supported (