快速下载

A user script that optimizes browser settings to improve download speeds.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        快速下载
// @namespace   http://tampermonkey.net/
// @version     0.1
// @description A user script that optimizes browser settings to improve download speeds.
// @match       *://*/*
// @grant       none
// ==/UserScript==
(function() {
  'use strict';

  // Disable HTTP2
  // HTTP2 can sometimes cause slower download speeds, especially on older browsers.
  disableHTTP2();

  // Disable QUIC
  // QUIC can also cause slower download speeds on some networks.
  disableQUIC();

  // Increase the number of parallel downloads
  // By default, browsers limit the number of simultaneous downloads to reduce server load.
  increaseParallelDownloads();

  // Increase the download buffer size
  // A larger download buffer can help prevent pauses in downloads due to network fluctuations.
  increaseDownloadBufferSize();

  // Disable slow connection detection
  // This can prevent the browser from slowing down downloads on perceived slow connections.
  disableSlowConnectionDetection();

  // Enable direct download link resolution
  // Some browsers hide the direct download link behind a "Download" button, which can add extra time.
  enableDirectDownloadLinkResolution();

  // Disable anti-virus scanning
  // Anti-virus software can slow down downloads by scanning files as they are downloaded.
  disableAntiVirusScanning();

  // Disable browser extensions
  // Some browser extensions can interfere with downloads, especially those that modify network settings.
  disableBrowserExtensions();

  // Log the changes made for debugging purposes
  console.log('Faster Browser Downloads settings have been applied.');

  // Helper functions

  function disableHTTP2() {
    console.info('Disabling HTTP2');
    if (window.HTTP2) {
      window.HTTP2.disable();
    }
  }

  function disableQUIC() {
    console.info('Disabling QUIC');
    if (window.QUIC) {
      window.QUIC.disable();
    }
  }

  function increaseParallelDownloads() {
    console.info('Increasing parallel downloads');
    if (navigator.maxConnectionsPerHost) {
      navigator.maxConnectionsPerHost = 32;
    }
  }

  function increaseDownloadBufferSize() {
    console.info('Increasing download buffer size');
    if (window.chrome) {
      chrome.webRequest.onBeforeRequest.addListener(
        function(details) {
          console.info('Increasing download buffer size for: ' + details.url);
          if (details.method === 'GET') {
            details.requestHeaders.push(
              {name: 'Range', value: 'bytes=0-'}
            );
          }
          return {requestHeaders: details.requestHeaders};
        },
        {urls: ['*://*/*']},
        ['blocking', 'requestHeaders']
      );
    } else if (window.safari) {
      safari.extension.settings.set('increaseDownloadBufferSize', true);
    }
  }

  function disableSlowConnectionDetection() {
    console.info('Disabling slow connection detection');
    if (window.chrome) {
      chrome.webRequest.onBeforeRequest.addListener(
        function(details) {
          if (details.method === 'GET') {
            details.requestHeaders.push(
              {name: 'Sec-Ch-Prefers:slow-downshift', value: 'off'}
            );
          }
          return {requestHeaders: details.requestHeaders};
        },
        {urls: ['*://*/*']},
        ['blocking', 'requestHeaders']
      );
    } else if (window.safari) {
      safari.extension.settings.set('disableSlowConnectionDetection', true);
    }
  }

  function enableDirectDownloadLinkResolution() {
    console.info('Enabling direct download link resolution');
    if (window.chrome) {
      chrome.webRequest.onBeforeRequest.addListener(
        function(details) {
          console.info('Resolving direct download link for: ' + details.url);
          if (details.method === 'GET' && details.url.includes('/download/')) {
            details.redirectUrl = details.url.replace('/download/', '/file/');
          }
          return {redirectUrl: details.redirectUrl};
        },
        {urls: ['*://*/*']},
        ['blocking', 'redirect']
      );
    }
  }

  function disableAntiVirusScanning() {
    console.info('Disabling anti-virus scanning');
    if (window.chrome) {
      chrome.webRequest.onBeforeRequest.addListener(
        function(details) {
          if (details.method === 'GET' && details.url.includes('.exe')) {
            details.requestHeaders.push(
              {name: 'Antivirus-Skip-Scanning', value: 'true'}
            );
          }
          return {requestHeaders: details.requestHeaders};
        },
        {urls: ['*://*/*']},
        ['blocking', 'requestHeaders']
      );
    }
  }

  function disableBrowserExtensions() {
    console.info('Disabling browser extensions');
    if (window.chrome) {
      chrome.management.getAll(function(extensions) {
        for (var i = 0; i < extensions.length; i++) {
          if (extensions[i].enabled) {
            chrome.management.disable(extensions[i].id, function() {
              console.info('Disabled extension: ' + extensions[i].name);
            });
          }
        }
      });
    } else if (window.safari) {
      safari.extension.settings.set('disableBrowserExtensions', true);
    }
  }
})();