Modify Accept-Language Header

Force Accept-Language header to include en-US and zh-CN

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Modify Accept-Language Header
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Force Accept-Language header to include en-US and zh-CN
// @author       You
// @match        *://*/*
// @grant        none
// @license      MIT 
// ==/UserScript==

(function() {
    'use strict';

    // Intercept and modify XMLHttpRequest to change headers
    var open = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function() {
        this.addEventListener('readystatechange', function() {
            if (this.readyState === 4) {
                // Set both en-US and zh-CN in the Accept-Language header
                this.setRequestHeader('Accept-Language', 'en-US,en;q=0.9,zh-CN,zh;q=0.8');
            }
        });
        open.apply(this, arguments);
    };

    // Intercept fetch to modify headers
    var originalFetch = window.fetch;
    window.fetch = function() {
        arguments[1] = arguments[1] || {};
        arguments[1].headers = arguments[1].headers || {};
        // Set both en-US and zh-CN in the Accept-Language header
        arguments[1].headers['Accept-Language'] = 'en-US,en;q=0.9,zh-CN,zh;q=0.8';
        return originalFetch.apply(this, arguments);
    };
})();