Bypass the GitLab & GitHub Region Restriction

Bypass the GitLab Region Restriction by modifying the navigator.language field

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Bypass the GitLab & GitHub Region Restriction
// @namespace    http://tampermonkey.net/
// @version      0.6.0
// @description  Bypass the GitLab Region Restriction by modifying the navigator.language field
// @author       Lucas
// @match        https://*.gitlab.com/*
// @match        https://*.github.com/*
// @grant        GM_registerMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// @license      GPLv3
// @icon         https://www.gitlab.com/favicon.png
// ==/UserScript==

(function() {
  'use strict';

  let isEnabled = GM_getValue('isEnabled', false);

  function toggleBypass() {
      isEnabled = !isEnabled;
      GM_setValue('isEnabled', isEnabled);
      alert(`Bypass is now ${isEnabled ? 'enabled' : 'disabled'}`);
      location.reload();
  }

  const icon = isEnabled ? '✅' : '❌';
  GM_registerMenuCommand('Toggle Bypass (current: ' + (isEnabled ? 'enabled' : 'disabled') + ')', toggleBypass, icon);

  const originalLanguage = 'zh-CN';
  const newLanguage = 'en-US';

  Object.defineProperty(navigator, 'language', {
      get: function() {
          return isEnabled ? newLanguage : originalLanguage;
      }
  });

  Object.defineProperty(navigator, 'languages', {
      get: function() {
          return isEnabled ? [newLanguage] : [originalLanguage];
      }
  });

  const originalOpen = XMLHttpRequest.prototype.open;
  XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
    this.addEventListener('readystatechange', function() {
      if (this.readyState === 1 && isEnabled) {
        this.setRequestHeader('Accept-Language', 'en-US');
      }
    });
    originalOpen.apply(this, arguments);
  };
  
})();