super fast load

Enhance your browsing with Super Fast Load! Stop YouTube autoplay, add download buttons, and block ads, pop-ups, and trackers. Speed up slow connections, save data, and preload links for quick access. Hide cookie banners, disable location tracking, and block unnecessary scripts. Optimize for VPN/Tor, lazy load images and videos, and boost download speeds. Improve website loading by optimizing media elements and reducing ad buffering. Experience faster, safer browsing today!

  1. // ==UserScript==
  2. // @name super fast load
  3. // @namespace http://tampermonkey.net/
  4. // @version 3
  5. // @description Enhance your browsing with Super Fast Load! Stop YouTube autoplay, add download buttons, and block ads, pop-ups, and trackers. Speed up slow connections, save data, and preload links for quick access. Hide cookie banners, disable location tracking, and block unnecessary scripts. Optimize for VPN/Tor, lazy load images and videos, and boost download speeds. Improve website loading by optimizing media elements and reducing ad buffering. Experience faster, safer browsing today!
  6. // @match *://*/*
  7. // @grant GM_xmlhttpRequest
  8. // @grant unsafeWindow
  9. // @require https://cdn.jsdelivr.net/npm/brotli@1.3.0/umd/browser/brotli.min.js
  10. // @require https://cdnjs.cloudflare.com/ajax/libs/zstd/1.3.8/zstd.min.js
  11. // @connect * // این خط برای جلوگیری از پیغام دسترسی به منابع بین‌مرزی است
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. const CONFIG = {
  18. resourceCache: new Map(),
  19. blockList: ['ads.example.com', 'tracking.example.com'],
  20. nonEssentialSelectors: ['script[src*="tracking"]', 'iframe[src*="advertisement"]', '.ad-banner', '.cookie-consent'],
  21. criticalResources: ['https://example.com/styles.css', 'https://example.com/script.js'],
  22. timeout: 500,
  23. maxRetries: 3,
  24. retryDelay: 1000,
  25. imageQuality: 50,
  26. preloadThreshold: 500,
  27. minifyCSS: true,
  28. minifyJS: true,
  29. };
  30.  
  31. // Fetch with timeout
  32. const fetchWithTimeout = async (url, options = {}) => {
  33. const controller = new AbortController();
  34. const timeoutId = setTimeout(() => controller.abort(), CONFIG.timeout);
  35. try {
  36. const response = await fetch(url, { ...options, signal: controller.signal });
  37. clearTimeout(timeoutId);
  38. return response;
  39. } catch (error) {
  40. clearTimeout(timeoutId);
  41. throw error;
  42. }
  43. };
  44.  
  45. // Inject CSS
  46. const injectCSS = (css) => {
  47. const style = document.createElement('style');
  48. style.textContent = css;
  49. document.head.appendChild(style);
  50. };
  51.  
  52. // Preload links
  53. const preloadLinks = () => {
  54. const links = document.querySelectorAll('a[href]');
  55. links.forEach(link => {
  56. if (!CONFIG.resourceCache.has(link.href)) {
  57. const linkElement = document.createElement('link');
  58. linkElement.rel = 'prefetch';
  59. linkElement.href = link.href;
  60. document.head.appendChild(linkElement);
  61. CONFIG.resourceCache.set(link.href, true);
  62. }
  63. });
  64. };
  65.  
  66. // Compress images
  67. const compressImage = async (img) => {
  68. const canvas = document.createElement('canvas');
  69. const ctx = canvas.getContext('2d');
  70. canvas.width = img.naturalWidth;
  71. canvas.height = img.naturalHeight;
  72. ctx.drawImage(img, 0, 0);
  73. const compressedDataUrl = canvas.toDataURL('image/jpeg', CONFIG.imageQuality / 100);
  74. img.src = compressedDataUrl;
  75. };
  76.  
  77. // Optimize images
  78. const optimizeImages = async () => {
  79. const images = document.querySelectorAll('img');
  80. images.forEach(async (img) => {
  81. if (img.complete && img.naturalWidth > 0) {
  82. await compressImage(img);
  83. }
  84. });
  85. };
  86.  
  87. // Minify CSS
  88. const minifyCSS = (css) => {
  89. return css.replace(/\s+/g, ' ').trim();
  90. };
  91.  
  92. // Minify JS
  93. const minifyJS = (js) => {
  94. return js.replace(/\s+/g, ' ').trim();
  95. };
  96.  
  97. // Minify resources
  98. const minifyResources = async (url) => {
  99. const response = await fetch(url);
  100. if (!response.ok) throw new Error('Network response was not ok');
  101. const text = await response.text();
  102. if (url.endsWith('.css') && CONFIG.minifyCSS) {
  103. return minifyCSS(text);
  104. } else if (url.endsWith('.js') && CONFIG.minifyJS) {
  105. return minifyJS(text);
  106. }
  107. return text;
  108. };
  109.  
  110. // Load resource
  111. const loadResource = async (url, type) => {
  112. try {
  113. const text = await minifyResources(url);
  114. const blob = new Blob([text], { type: type === 'css' ? 'text/css' : 'application/javascript' });
  115. const blobUrl = URL.createObjectURL(blob);
  116. const element = document.createElement(type === 'css' ? 'link' : 'script');
  117. element[type === 'css' ? 'href' : 'src'] = blobUrl;
  118. element.rel = type === 'css' ? 'stylesheet' : undefined;
  119. element.defer = type !== 'css';
  120. document.head.appendChild(element);
  121. } catch (error) {
  122. console.error('Failed to load resource:', url, error);
  123. }
  124. };
  125.  
  126. // Preload critical resources
  127. const preloadResources = () => {
  128. CONFIG.criticalResources.forEach(resource => {
  129. loadResource(resource, resource.endsWith('.css') ? 'css' : 'js');
  130. });
  131. };
  132.  
  133. // Block unnecessary requests
  134. const blockUnnecessaryRequests = () => {
  135. const originalOpen = XMLHttpRequest.prototype.open;
  136. XMLHttpRequest.prototype.open = function (method, url, ...args) {
  137. if (url.includes('captcha') || url.includes('cloudflare')) {
  138. return originalOpen.call(this, method, url, ...args);
  139. }
  140. if (CONFIG.blockList.some(domain => url.includes(domain))) {
  141. console.log(`Blocked request to: ${url}`);
  142. return;
  143. }
  144. return originalOpen.call(this, method, url, ...args);
  145. };
  146. };
  147.  
  148. // Prevent data collection
  149. const preventDataCollection = () => {
  150. navigator.geolocation.getCurrentPosition = () => console.warn("Geolocation access blocked.");
  151. Object.defineProperty(navigator, 'userAgent', { get: () => 'Blocked User Agent' });
  152. };
  153.  
  154. // Remove non-essential elements
  155. const removeNonEssentialElements = () => {
  156. CONFIG.nonEssentialSelectors.forEach(selector => {
  157. document.querySelectorAll(selector).forEach(element => {
  158. if (!element.src?.includes('captcha') && !element.src?.includes('cloudflare')) {
  159. element.remove();
  160. }
  161. });
  162. });
  163. };
  164.  
  165. // Prevent autoplay without breaking video controls
  166. const preventAutoplay = () => {
  167. const stopAutoplay = (media) => {
  168. media.pause(); // Stop autoplay
  169. media.preload = 'none'; // Prevent preloading
  170. media.autoplay = false; // Disable autoplay
  171. media.setAttribute('data-autoplay-prevented', 'true'); // Mark video as autoplay prevented
  172.  
  173. // Control play/pause with mouse click
  174. media.addEventListener('click', (event) => {
  175. event.stopPropagation(); // Prevent event propagation
  176. if (media.paused) {
  177. media.play(); // Play if paused
  178. } else {
  179. media.pause(); // Pause if playing
  180. }
  181. });
  182.  
  183. media.controls = false; // Disable default video controls
  184.  
  185. // Hide large/small play buttons (if present)
  186. const playButton = media.closest('.ytp-large-play-button, .ytp-small-play-button');
  187. if (playButton) {
  188. playButton.style.display = 'none';
  189. }
  190. };
  191.  
  192. // Apply settings to all video and audio elements on the page
  193. document.querySelectorAll('video, audio').forEach(stopAutoplay);
  194.  
  195. // Observe DOM changes to apply settings to new video and audio elements
  196. const observer = new MutationObserver((mutations) => {
  197. mutations.forEach((mutation) => {
  198. if (mutation.type === 'childList') {
  199. mutation.addedNodes.forEach((node) => {
  200. if (node.nodeName === 'VIDEO' || node.nodeName === 'AUDIO') {
  201. stopAutoplay(node);
  202. } else if (node.querySelectorAll) {
  203. node.querySelectorAll('video, audio').forEach(stopAutoplay);
  204. }
  205. });
  206. }
  207. });
  208. });
  209.  
  210. // Start observing the document body for changes
  211. observer.observe(document.body, { childList: true, subtree: true });
  212. };
  213.  
  214. // Lazy load media
  215. const lazyLoadMedia = () => {
  216. const observer = new IntersectionObserver(entries => {
  217. entries.forEach(async entry => {
  218. if (entry.isIntersecting) {
  219. const media = entry.target;
  220. const response = await fetch(media.dataset.src);
  221. if (response.ok) {
  222. const blob = await response.blob();
  223. media.src = URL.createObjectURL(blob);
  224. observer.unobserve(media);
  225. }
  226. }
  227. });
  228. }, { threshold: 0.1, rootMargin: '200px' });
  229.  
  230. document.querySelectorAll('video[data-src], audio[data-src], img[data-src]').forEach(media => observer.observe(media));
  231. };
  232.  
  233. // Enable lazy loading for images
  234. const enableLazyLoadImages = () => {
  235. document.querySelectorAll('img:not([loading])').forEach(img => {
  236. img.loading = 'lazy';
  237. img.decoding = 'async';
  238. img.referrerPolicy = 'no-referrer';
  239. });
  240. };
  241.  
  242. // Create download button
  243. const createDownloadButton = () => {
  244. const downloadIcon = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
  245. downloadIcon.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
  246. downloadIcon.setAttribute('fill', 'currentColor');
  247. downloadIcon.setAttribute('height', '24');
  248. downloadIcon.setAttribute('viewBox', '0 0 24 24');
  249. downloadIcon.setAttribute('width', '24');
  250. downloadIcon.setAttribute('focusable', 'false');
  251. downloadIcon.style.pointerEvents = 'none';
  252. downloadIcon.style.display = 'block';
  253. downloadIcon.style.width = '100%';
  254. downloadIcon.style.height = '100%';
  255. downloadIcon.style.opacity = '0.2';
  256.  
  257. const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
  258. path.setAttribute('d', 'M17 18v1H6v-1h11zm-.5-6.6-.7-.7-3.8 3.7V4h-1v10.4l-3.8-3.8-.7.7 5 5 5-4.9z');
  259. downloadIcon.appendChild(path);
  260.  
  261. const downloadButton = document.createElement('button');
  262. downloadButton.id = 'ytdl-download-button';
  263. downloadButton.classList.add('ytp-button');
  264. downloadButton.title = 'Left click to download as video, right click as audio only';
  265. downloadButton.appendChild(downloadIcon);
  266.  
  267. const interval = setInterval(() => {
  268. const controls = document.querySelector('.ytp-right-controls');
  269. if (controls && !document.getElementById('ytdl-download-button')) {
  270. controls.insertBefore(downloadButton, controls.firstChild);
  271. clearInterval(interval);
  272. }
  273. }, 1000);
  274.  
  275. downloadButton.addEventListener('click', (event) => {
  276. if (event.button === 0) {
  277. showModal();
  278. } else if (event.button === 2) {
  279. showModal(true);
  280. }
  281. });
  282. };
  283.  
  284. // Show modal
  285. const showModal = (isAudioOnly = false) => {
  286. const overlay = document.createElement('div');
  287. overlay.id = 'modal-overlay';
  288. overlay.onclick = hideModal;
  289.  
  290. const modalContent = document.createElement('div');
  291. modalContent.id = 'modal-content';
  292.  
  293. const iframe = document.createElement('iframe');
  294. const videoID = new URLSearchParams(window.location.search).get('v');
  295. if (videoID) {
  296. const url = isAudioOnly ? `https://www.y2mate.com/youtube/${videoID}/audio` : `https://www.y2mate.com/youtube/${videoID}`;
  297. iframe.src = url;
  298. }
  299. modalContent.appendChild(iframe);
  300. overlay.appendChild(modalContent);
  301. document.body.appendChild(overlay);
  302.  
  303. overlay.style.display = 'flex';
  304. };
  305.  
  306. // Hide modal
  307. const hideModal = () => {
  308. document.getElementById('modal-overlay')?.remove();
  309. };
  310.  
  311. // Monitor connection
  312. const monitorConnection = async () => {
  313. while (true) {
  314. try {
  315. const response = await fetch('https://www.google.com/generate_204', { method: 'GET', mode: 'no-cors' });
  316. if (response.status >= 200 && response.status < 300) {
  317. console.log("Internet is stable.");
  318. } else {
  319. throw new Error("Connectivity issue detected.");
  320. }
  321. } catch (error) {
  322. console.warn("Internet connection lost! Attempting to reconnect...");
  323. reconnectNetwork();
  324. }
  325. await new Promise(resolve => setTimeout(resolve, 3000));
  326. }
  327. };
  328.  
  329. // Reconnect network
  330. const reconnectNetwork = async () => {
  331. console.log("Reconnecting to the network...");
  332. try {
  333. await clearDNSCache();
  334. console.log("DNS cache cleared.");
  335. navigator.serviceWorker.getRegistrations().then(registrations => {
  336. registrations.forEach(reg => reg.unregister());
  337. console.log("Service workers reset.");
  338. });
  339. if (navigator.connection && navigator.connection.type) {
  340. navigator.connection.type = "wifi";
  341. console.log("Network interface reinitialized.");
  342. }
  343. console.log("Reconnection attempt completed.");
  344. } catch (error) {
  345. console.error("Error during reconnection process:", error);
  346. }
  347. };
  348.  
  349. // Clear DNS cache
  350. const clearDNSCache = async () => {
  351. try {
  352. await Promise.all([
  353. fetch('https://1.1.1.1/generate_204', { method: 'GET', mode: 'no-cors' }),
  354. fetch('https://8.8.8.8/generate_204', { method: 'GET', mode: 'no-cors' }),
  355. ]);
  356. console.log("DNS cache refreshed.");
  357. } catch (error) {
  358. console.warn("Failed to refresh DNS cache:", error);
  359. }
  360. };
  361.  
  362. // Enhance request stability
  363. const enhanceRequestStability = () => {
  364. const originalFetch = window.fetch;
  365. window.fetch = async (...args) => {
  366. for (let attempt = 1; attempt <= CONFIG.maxRetries; attempt++) {
  367. try {
  368. const response = await originalFetch(...args);
  369. if (response.ok) return response;
  370. } catch (error) {
  371. console.warn(`Fetch attempt ${attempt} failed. Retrying...`, error);
  372. }
  373. await new Promise(resolve => setTimeout(resolve, CONFIG.retryDelay));
  374. }
  375. console.error("Fetch failed after 5 retries.");
  376. throw new Error("Failed to stabilize request.");
  377. };
  378.  
  379. const originalXMLHttpRequest = window.XMLHttpRequest;
  380. window.XMLHttpRequest = function () {
  381. const xhr = new originalXMLHttpRequest();
  382. xhr.addEventListener("error", () => {
  383. console.warn("XHR failed. Retrying...");
  384. setTimeout(() => xhr.open(xhr.method, xhr.url, true), CONFIG.retryDelay);
  385. });
  386. return xhr;
  387. };
  388. };
  389.  
  390. // Optimize based on conditions
  391. const optimizeBasedOnConditions = async () => {
  392. const networkInfo = await getNetworkInfo();
  393. const deviceInfo = getDeviceInfo();
  394.  
  395. console.log('Network Info:', networkInfo);
  396. console.log('Device Info:', deviceInfo);
  397.  
  398. if (networkInfo.effectiveType === 'slow-2g' || networkInfo.effectiveType === '2g') {
  399. console.log('Slow network detected. Applying aggressive optimizations...');
  400. preloadResources();
  401. enhanceRequestStability();
  402. enableLazyLoadImages();
  403. optimizeImages();
  404. } else if (networkInfo.effectiveType === '3g') {
  405. console.log('3G network detected. Applying moderate optimizations...');
  406. preloadResources();
  407. enableLazyLoadImages();
  408. optimizeImages();
  409. } else {
  410. console.log('Fast network detected. Applying light optimizations...');
  411. enableLazyLoadImages();
  412. optimizeImages();
  413. }
  414. };
  415.  
  416. // Check if mobile
  417. const isMobile = () => window.matchMedia('(max-width: 768px)').matches;
  418.  
  419. // Save mobile resources
  420. const saveMobileResources = () => {
  421. const elements = document.querySelectorAll('img[src], video[src], script[src], link[rel="stylesheet"]');
  422. const mobileResources = new Set();
  423. elements.forEach(el => {
  424. const src = el.src || el.href;
  425. if (src) {
  426. mobileResources.add(src);
  427. }
  428. });
  429. sessionStorage.setItem('mobileResources', JSON.stringify([...mobileResources]));
  430. console.log('Mobile resources captured:', [...mobileResources]);
  431. };
  432.  
  433. // Block desktop resources
  434. const blockDesktopResources = () => {
  435. const storedResources = sessionStorage.getItem('mobileResources');
  436. if (!storedResources) {
  437. console.warn('No mobile resources found. Please visit the site in mobile mode first.');
  438. return;
  439. }
  440. const mobileResources = new Set(JSON.parse(storedResources));
  441.  
  442. const blockRequest = (url) => {
  443. if (!mobileResources.has(url)) {
  444. console.warn(`Blocked desktop-only resource: ${url}`);
  445. return true;
  446. }
  447. return false;
  448. };
  449.  
  450. const originalFetch = window.fetch;
  451. window.fetch = function (...args) {
  452. if (blockRequest(args[0])) {
  453. return Promise.reject(new Error('Blocked by Tampermonkey script'));
  454. }
  455. return originalFetch.apply(this, args);
  456. };
  457.  
  458. const originalXHR = window.XMLHttpRequest.prototype.open;
  459. window.XMLHttpRequest.prototype.open = function (method, url, ...rest) {
  460. if (blockRequest(url)) {
  461. console.warn(`Blocked XHR request: ${url}`);
  462. return;
  463. }
  464. return originalXHR.apply(this, [method, url, ...rest]);
  465. };
  466. };
  467.  
  468. // Improve page cache
  469. const improvePageCache = () => {
  470. const cacheKey = 'pageCache';
  471. const cachedData = localStorage.getItem(cacheKey);
  472. if (cachedData) {
  473. const parsedData = JSON.parse(cachedData);
  474. console.log('Loaded from cache:', parsedData);
  475. } else {
  476. console.log('No cache found. Creating new cache...');
  477. localStorage.setItem(cacheKey, JSON.stringify({ timestamp: Date.now(), data: 'example data' }));
  478. }
  479. };
  480.  
  481. // Lazy load all elements
  482. const lazyLoadAllElements = () => {
  483. const observer = new IntersectionObserver(entries => {
  484. entries.forEach(entry => {
  485. if (entry.isIntersecting) {
  486. const element = entry.target;
  487. if (element.tagName === 'IMG' && element.dataset.src) {
  488. element.src = element.dataset.src;
  489. } else if (element.tagName === 'VIDEO' && element.dataset.src) {
  490. element.src = element.dataset.src;
  491. } else if (element.tagName === 'IFRAME' && element.dataset.src) {
  492. element.src = element.dataset.src;
  493. } else if (element.tagName === 'DIV' && element.dataset.style) {
  494. element.style = element.dataset.style;
  495. }
  496. observer.unobserve(element);
  497. }
  498. });
  499. }, { threshold: 0.1, rootMargin: '200px' });
  500.  
  501. document.querySelectorAll('img[data-src], video[data-src], iframe[data-src], div[data-style]').forEach(element => observer.observe(element));
  502. };
  503.  
  504. // Function to optimize media elements
  505. const optimizeMediaElements = () => {
  506. const mediaElements = document.querySelectorAll('video, audio');
  507. mediaElements.forEach(media => {
  508. media.preload = 'auto';
  509. media.autoplay = false;
  510. media.loop = false;
  511. media.controls = true;
  512. media.muted = false;
  513. });
  514. };
  515.  
  516. // Function to block ad-related scripts
  517. const blockAdScripts = () => {
  518. const scripts = document.querySelectorAll('script');
  519. scripts.forEach(script => {
  520. if (script.src && script.src.includes('ads')) {
  521. script.remove();
  522. }
  523. });
  524. };
  525.  
  526. // Function to optimize network requests
  527. const optimizeNetworkRequests = () => {
  528. const originalFetch = window.fetch;
  529. window.fetch = function(resource, init) {
  530. const url = typeof resource === 'string' ? resource : resource.url;
  531. if (url.includes('ads') || url.includes('tracking')) {
  532. return Promise.reject(new Error('Blocked ad or tracking request'));
  533. }
  534. return originalFetch(resource, init);
  535. };
  536. };
  537.  
  538. // Function to delay non-essential scripts
  539. const delayNonEssentialScripts = () => {
  540. const scripts = document.querySelectorAll('script[type="text/javascript"]');
  541. scripts.forEach(script => {
  542. if (!script.src && !script.async && !script.defer) {
  543. script.defer = true;
  544. }
  545. });
  546. };
  547.  
  548. // Inject CSS
  549. injectCSS(`
  550. #ytdl-download-button {
  551. position: relative;
  552. top: 0;
  553. left: 0;
  554. background-color: transparent;
  555. border: none;
  556. cursor: pointer;
  557. z-index: 1000;
  558. }
  559.  
  560. #modal-overlay {
  561. position: fixed;
  562. top: 0;
  563. left: 0;
  564. width: 100%;
  565. height: 100%;
  566. background-color: rgba(0, 0, 0, 0.5);
  567. display: none;
  568. justify-content: center;
  569. align-items: center;
  570. z-index: 2000;
  571. }
  572.  
  573. #modal-content {
  574. background-color: white;
  575. padding: 20px;
  576. border-radius: 8px;
  577. width: 80%;
  578. max-width: 600px;
  579. }
  580.  
  581. #modal-content iframe {
  582. width: 100%;
  583. height: 400px;
  584. border: none;
  585. }
  586.  
  587. .ytp-large-play-button, .ytp-small-play-button {
  588. display: none !important;
  589. }
  590.  
  591. video::-webkit-media-controls {
  592. display: none !important;
  593. }
  594. `);
  595.  
  596. // Initialize optimizations
  597. preloadResources();
  598. monitorConnection();
  599. enhanceRequestStability();
  600. optimizeBasedOnConditions();
  601. blockUnnecessaryRequests();
  602. preventDataCollection();
  603. removeNonEssentialElements();
  604. preventAutoplay();
  605. lazyLoadMedia();
  606. enableLazyLoadImages();
  607. optimizeImages();
  608. preloadLinks();
  609. improvePageCache();
  610. lazyLoadAllElements();
  611. optimizeMediaElements();
  612. blockAdScripts();
  613. optimizeNetworkRequests();
  614. delayNonEssentialScripts();
  615.  
  616. // Event listeners
  617. window.addEventListener('yt-navigate-finish', () => {
  618. preventAutoplay();
  619. createDownloadButton();
  620. });
  621.  
  622. window.addEventListener('load', () => {
  623. preventAutoplay();
  624. createDownloadButton();
  625. });
  626.  
  627. const originalPushState = history.pushState;
  628. history.pushState = function() {
  629. originalPushState.apply(this, arguments);
  630. preventAutoplay();
  631. };
  632.  
  633. const originalReplaceState = history.replaceState;
  634. history.replaceState = function() {
  635. originalReplaceState.apply(this, arguments);
  636. preventAutoplay();
  637. };
  638.  
  639. // Mobile/desktop detection
  640. if (isMobile()) {
  641. console.log('Mobile mode detected. Capturing resources...');
  642. saveMobileResources();
  643. } else {
  644. console.log('Desktop mode detected. Blocking extra resources...');
  645. blockDesktopResources();
  646. }
  647.  
  648. console.log("Ultimate Page Load Optimizer with Advanced Lazy Loading and Speed Up Website Loading is active.");
  649. })();