Skip to content

Instantly share code, notes, and snippets.

@misaka00251
Created March 10, 2021 10:56
Show Gist options
  • Save misaka00251/b9d7d3c910739e16eef02cddc408f76d to your computer and use it in GitHub Desktop.
Save misaka00251/b9d7d3c910739e16eef02cddc408f76d to your computer and use it in GitHub Desktop.
Google always in com (no safesearch)

If you visit Google search from China, the SafeSearch option will on by default, and you can't turn it off (because it's already off in search settings). Login to Google will not solve this.

Visit Google's Non Country Redirection feature first will solve this problem. This userscript will automatically solve this issue for you. However, you need to wait when you perform a search request for the first time.

Tested in Violentmonkey.

Special thanks to @mengzonefire & the original author @opsomh.

// ==UserScript==
// @name Google always in com
// @version v2021.03.10
// @description Redirects Google from local TLD to ".com" top level domain (ncr, no country redirect, gws_rd)
// @namespace https://greasyfork.org/en/users/30-opsomh
// @include *.google.*/*
// @include *.blogspot.*/*
// @exclude *.google.com/*
// @exclude *.blogspot.com/*
// @grant GM_xmlhttpRequest
// @inject-into auto
// @run-at document-start
// ==/UserScript==
var url = new URL(location.href);
//http://techxt.com/list-of-all-google-domains/1373/
//https://www.google.com/supported_domains
//https://ipfs.io/ipfs/QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco/wiki/List_of_Google_domains.html
var re = /(\.google|\.blogspot)\.[a-z]{2,3}(?:\.[a-z]{2})?$/;
if(re.test(url.hostname))
{
window.stop();
GM_xmlhttpRequest({
url: 'https://google.com/ncr',
type: 'GET',
onload: function (r) {
console.log('Google always in com:', url.hostname);
url.searchParams.set('gws_rd', 'cr');
url.hostname = url.hostname.replace(re, '$1.com');
location.assign(url.href);
},
onerror: function (r) {
alert('request error');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment