ACT.谷歌.DM.NCR

没有国家重定向,轻松切换区域/语言。

目前为 2022-04-06 提交的版本。查看 最新版本

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

QingJ © 2025

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