Modify Accept-Language Header

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

Verze ze dne 23. 09. 2024. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

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