ACT.Google.DM.NCR

No country redirect, easy to switch region/language.

目前為 2022-05-03 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name ACT.Google.DM.NCR
  3. // @name:zh-CN ACT.谷歌.DM.NCR
  4. // @description No country redirect, easy to switch region/language.
  5. // @description:zh-CN 没有国家重定向,轻松切换区域/语言。
  6. // @author ACTCD
  7. // @version 20220504.2
  8. // @license GPL-3.0-or-later
  9. // @namespace ACTCD/Userscripts
  10. // @supportURL https://github.com/ACTCD/Userscripts#contact
  11. // @homepageURL https://github.com/ACTCD/Userscripts
  12. // @match *://*.google.com/*
  13. // @match *://*.google.ad/*
  14. // @match *://*.google.ae/*
  15. // @match *://*.google.com.af/*
  16. // @match *://*.google.com.ag/*
  17. // @match *://*.google.com.ai/*
  18. // @match *://*.google.al/*
  19. // @match *://*.google.am/*
  20. // @match *://*.google.co.ao/*
  21. // @match *://*.google.com.ar/*
  22. // @match *://*.google.as/*
  23. // @match *://*.google.at/*
  24. // @match *://*.google.com.au/*
  25. // @match *://*.google.az/*
  26. // @match *://*.google.ba/*
  27. // @match *://*.google.com.bd/*
  28. // @match *://*.google.be/*
  29. // @match *://*.google.bf/*
  30. // @match *://*.google.bg/*
  31. // @match *://*.google.com.bh/*
  32. // @match *://*.google.bi/*
  33. // @match *://*.google.bj/*
  34. // @match *://*.google.com.bn/*
  35. // @match *://*.google.com.bo/*
  36. // @match *://*.google.com.br/*
  37. // @match *://*.google.bs/*
  38. // @match *://*.google.bt/*
  39. // @match *://*.google.co.bw/*
  40. // @match *://*.google.by/*
  41. // @match *://*.google.com.bz/*
  42. // @match *://*.google.ca/*
  43. // @match *://*.google.cd/*
  44. // @match *://*.google.cf/*
  45. // @match *://*.google.cg/*
  46. // @match *://*.google.ch/*
  47. // @match *://*.google.ci/*
  48. // @match *://*.google.co.ck/*
  49. // @match *://*.google.cl/*
  50. // @match *://*.google.cm/*
  51. // @match *://*.google.cn/*
  52. // @match *://*.google.com.co/*
  53. // @match *://*.google.co.cr/*
  54. // @match *://*.google.com.cu/*
  55. // @match *://*.google.cv/*
  56. // @match *://*.google.com.cy/*
  57. // @match *://*.google.cz/*
  58. // @match *://*.google.de/*
  59. // @match *://*.google.dj/*
  60. // @match *://*.google.dk/*
  61. // @match *://*.google.dm/*
  62. // @match *://*.google.com.do/*
  63. // @match *://*.google.dz/*
  64. // @match *://*.google.com.ec/*
  65. // @match *://*.google.ee/*
  66. // @match *://*.google.com.eg/*
  67. // @match *://*.google.es/*
  68. // @match *://*.google.com.et/*
  69. // @match *://*.google.fi/*
  70. // @match *://*.google.com.fj/*
  71. // @match *://*.google.fm/*
  72. // @match *://*.google.fr/*
  73. // @match *://*.google.ga/*
  74. // @match *://*.google.ge/*
  75. // @match *://*.google.gg/*
  76. // @match *://*.google.com.gh/*
  77. // @match *://*.google.com.gi/*
  78. // @match *://*.google.gl/*
  79. // @match *://*.google.gm/*
  80. // @match *://*.google.gr/*
  81. // @match *://*.google.com.gt/*
  82. // @match *://*.google.gy/*
  83. // @match *://*.google.hk/*
  84. // @match *://*.google.com.hk/*
  85. // @match *://*.google.hn/*
  86. // @match *://*.google.hr/*
  87. // @match *://*.google.ht/*
  88. // @match *://*.google.hu/*
  89. // @match *://*.google.co.id/*
  90. // @match *://*.google.ie/*
  91. // @match *://*.google.co.il/*
  92. // @match *://*.google.im/*
  93. // @match *://*.google.co.in/*
  94. // @match *://*.google.iq/*
  95. // @match *://*.google.is/*
  96. // @match *://*.google.it/*
  97. // @match *://*.google.je/*
  98. // @match *://*.google.com.jm/*
  99. // @match *://*.google.jo/*
  100. // @match *://*.google.jp/*
  101. // @match *://*.google.co.jp/*
  102. // @match *://*.google.co.ke/*
  103. // @match *://*.google.com.kh/*
  104. // @match *://*.google.ki/*
  105. // @match *://*.google.kg/*
  106. // @match *://*.google.co.kr/*
  107. // @match *://*.google.com.kw/*
  108. // @match *://*.google.kz/*
  109. // @match *://*.google.la/*
  110. // @match *://*.google.com.lb/*
  111. // @match *://*.google.li/*
  112. // @match *://*.google.lk/*
  113. // @match *://*.google.co.ls/*
  114. // @match *://*.google.lt/*
  115. // @match *://*.google.lu/*
  116. // @match *://*.google.lv/*
  117. // @match *://*.google.com.ly/*
  118. // @match *://*.google.co.ma/*
  119. // @match *://*.google.md/*
  120. // @match *://*.google.me/*
  121. // @match *://*.google.mg/*
  122. // @match *://*.google.mk/*
  123. // @match *://*.google.ml/*
  124. // @match *://*.google.com.mm/*
  125. // @match *://*.google.mn/*
  126. // @match *://*.google.ms/*
  127. // @match *://*.google.com.mt/*
  128. // @match *://*.google.mu/*
  129. // @match *://*.google.mv/*
  130. // @match *://*.google.mw/*
  131. // @match *://*.google.com.mx/*
  132. // @match *://*.google.com.my/*
  133. // @match *://*.google.co.mz/*
  134. // @match *://*.google.com.na/*
  135. // @match *://*.google.com.ng/*
  136. // @match *://*.google.com.ni/*
  137. // @match *://*.google.ne/*
  138. // @match *://*.google.nl/*
  139. // @match *://*.google.no/*
  140. // @match *://*.google.com.np/*
  141. // @match *://*.google.nr/*
  142. // @match *://*.google.nu/*
  143. // @match *://*.google.co.nz/*
  144. // @match *://*.google.com.om/*
  145. // @match *://*.google.com.pa/*
  146. // @match *://*.google.com.pe/*
  147. // @match *://*.google.com.pg/*
  148. // @match *://*.google.com.ph/*
  149. // @match *://*.google.com.pk/*
  150. // @match *://*.google.pl/*
  151. // @match *://*.google.pn/*
  152. // @match *://*.google.com.pr/*
  153. // @match *://*.google.ps/*
  154. // @match *://*.google.pt/*
  155. // @match *://*.google.com.py/*
  156. // @match *://*.google.com.qa/*
  157. // @match *://*.google.ro/*
  158. // @match *://*.google.ru/*
  159. // @match *://*.google.rw/*
  160. // @match *://*.google.com.sa/*
  161. // @match *://*.google.com.sb/*
  162. // @match *://*.google.sc/*
  163. // @match *://*.google.se/*
  164. // @match *://*.google.com.sg/*
  165. // @match *://*.google.sh/*
  166. // @match *://*.google.si/*
  167. // @match *://*.google.sk/*
  168. // @match *://*.google.com.sl/*
  169. // @match *://*.google.sn/*
  170. // @match *://*.google.so/*
  171. // @match *://*.google.sm/*
  172. // @match *://*.google.sr/*
  173. // @match *://*.google.st/*
  174. // @match *://*.google.com.sv/*
  175. // @match *://*.google.td/*
  176. // @match *://*.google.tg/*
  177. // @match *://*.google.co.th/*
  178. // @match *://*.google.com.tj/*
  179. // @match *://*.google.tl/*
  180. // @match *://*.google.tm/*
  181. // @match *://*.google.tn/*
  182. // @match *://*.google.to/*
  183. // @match *://*.google.com.tr/*
  184. // @match *://*.google.tt/*
  185. // @match *://*.google.com.tw/*
  186. // @match *://*.google.co.tz/*
  187. // @match *://*.google.com.ua/*
  188. // @match *://*.google.co.ug/*
  189. // @match *://*.google.co.uk/*
  190. // @match *://*.google.com.uy/*
  191. // @match *://*.google.co.uz/*
  192. // @match *://*.google.com.vc/*
  193. // @match *://*.google.co.ve/*
  194. // @match *://*.google.vg/*
  195. // @match *://*.google.co.vi/*
  196. // @match *://*.google.com.vn/*
  197. // @match *://*.google.vu/*
  198. // @match *://*.google.ws/*
  199. // @match *://*.google.rs/*
  200. // @match *://*.google.co.za/*
  201. // @match *://*.google.co.zm/*
  202. // @match *://*.google.co.zw/*
  203. // @match *://*.google.cat/*
  204. // @grant none
  205. // @run-at document-start
  206. // ==/UserScript==
  207. // https://www.google.com/supported_domains
  208.  
  209. (function () {
  210. 'use strict';
  211.  
  212. if (location.pathname == '/url') return;
  213. const lang = navigator.language || 'zh-CN';
  214. const _url = new URL(location);
  215. let url = new URL(location);
  216. url.searchParams.set("gl", lang.slice(-2));
  217. url.searchParams.set("hl", lang);
  218. url.searchParams.delete("client");
  219. const domain = 'google.com';
  220. let current_domian = location.hostname.match(/google\.[^\/]+/);
  221. current_domian &&= current_domian[0];
  222. if (current_domian != domain) {
  223. url.hostname = location.hostname.replace(current_domian, domain);
  224. if (url.hostname == 'www.google.com' && ['/', '/search'].includes(location.pathname)) {
  225. url.href = 'https://www.google.com/ncr#ncr:' + encodeURIComponent(url);
  226. }
  227. window.stop();
  228. location.replace(url);
  229. return;
  230. }
  231. if (_url.hash.slice(0, 5) == '#ncr:') {
  232. location.hash = '';
  233. window.stop();
  234. location.replace(decodeURIComponent(_url.hash.slice(5)));
  235. return;
  236. }
  237. if (_url.searchParams.has("client") || !_url.searchParams.get("gl") && !_url.searchParams.get("hl")) {
  238. window.stop();
  239. location.replace(url);
  240. return;
  241. }
  242.  
  243. const default_lang = 'en-US';
  244. if (default_lang == lang) return;
  245. const default_region = default_lang.slice(-2);
  246. const default_langua = default_lang.slice(0, -3);
  247. const current_region = lang.slice(-2);
  248. const current_langua = lang.slice(0, -3);
  249. const langbar = document.createElement('div');
  250. const langbar_region = document.createElement('div');
  251. const langbar_region_default = document.createElement('span');
  252. const langbar_region_current = document.createElement('span');
  253. const langbar_langua = document.createElement('div');
  254. const langbar_langua_default = document.createElement('span');
  255. const langbar_langua_current = document.createElement('span');
  256. langbar.className = 'act_langbar mnr-c';
  257. langbar_region.textContent = lang == 'zh-CN' ? '区域:' : 'REGION:';
  258. langbar_langua.textContent = lang == 'zh-CN' ? '语言:' : 'LANGUAGE:';
  259. langbar_region_default.textContent = default_region;
  260. langbar_region_current.textContent = current_region;
  261. langbar_langua_default.textContent = default_langua.toUpperCase();
  262. langbar_langua_current.textContent = current_langua.toUpperCase();
  263. langbar_region.append(langbar_region_default, langbar_region_current);
  264. langbar_langua.append(langbar_langua_default, langbar_langua_current);
  265. default_region != current_region && langbar.append(langbar_region);
  266. default_langua != current_langua && langbar.append(langbar_langua);
  267. switch (_url.searchParams.get("gl")) {
  268. case current_region: langbar_region_current.className = 'act'; break;
  269. case default_region: langbar_region_default.className = 'act'; break;
  270. }
  271. switch (_url.searchParams.get("hl")) {
  272. case lang: langbar_langua_current.className = 'act'; break;
  273. case default_lang: langbar_langua_default.className = 'act'; break;
  274. }
  275. url = new URL(location);
  276. langbar_region.addEventListener('click', event => {
  277. switch (_url.searchParams.get("gl")) {
  278. case current_region: url.searchParams.set("gl", default_region); break;
  279. default: url.searchParams.set("gl", current_region);
  280. }
  281. location.replace(url);
  282. }, true);
  283. langbar_langua.addEventListener('click', event => {
  284. switch (_url.searchParams.get("hl")) {
  285. case lang: url.searchParams.set("hl", default_lang); break;
  286. default: url.searchParams.set("hl", lang);
  287. }
  288. location.replace(url);
  289. }, true);
  290. const langbar_style = document.createElement('style');
  291. langbar_style.textContent = `
  292. .act_langbar {
  293. line-height: 2;
  294. margin-left: calc(var(--center-column-margin, 16px) - 10px);
  295. margin-bottom: 6px;
  296. user-select: none;
  297. -webkit-user-select: none;
  298. }
  299. @media (max-width: 760px) and (hover: none) {
  300. .act_langbar {
  301. padding: 5px;
  302. text-align: center;
  303. }
  304. }
  305. .act_langbar>div {
  306. display: inline-block;
  307. padding: 0px 10px;
  308. margin-block: 3px;
  309. margin-inline: 10px;
  310. border: 1.5px solid;
  311. border-radius: 20px;
  312. cursor: pointer;
  313. }
  314. .act_langbar span {
  315. margin-left: 10px;
  316. }
  317. .act_langbar span.act {
  318. padding: 1px 5px;
  319. border: 1px solid;
  320. border-radius: 20px;
  321. }
  322. `;
  323.  
  324. if (document.head) {
  325. document.head.append(langbar_style);
  326. } else {
  327. new MutationObserver((mutationList, observer) => {
  328. document.head && (observer.disconnect(), document.head.append(langbar_style));
  329. }).observe(document, { subtree: true, childList: true });
  330. }
  331.  
  332. if (document.querySelector('#appbar')) {
  333. document.querySelector('#appbar')?.after(langbar);
  334. } else {
  335. new MutationObserver((mutationList, observer) => {
  336. document.querySelector('#appbar') && (observer.disconnect(), document.querySelector('#appbar')?.after(langbar));
  337. }).observe(document, { subtree: true, childList: true });
  338. }
  339.  
  340. function DOMContentLoaded() {
  341. navigator.userAgent.includes('iPad') && !document.querySelector('#appbar') && document.querySelector('#st-card')?.closest('#main>div')?.after(langbar);
  342. }
  343.  
  344. if (document.readyState === 'loading') {
  345. document.addEventListener('DOMContentLoaded', DOMContentLoaded);
  346. } else {
  347. DOMContentLoaded();
  348. }
  349.  
  350. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址