Modify Accept-Language Header

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

As of 2024-09-23. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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);
    };
})();