ACT.Google.DM.NCR

No country redirect, easy to switch region/language.

目前為 2022-06-17 提交的版本,檢視 最新版本

  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 20220617.1
  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. // @noframes
  207. // ==/UserScript==
  208. // https://www.google.com/supported_domains
  209.  
  210. (function () {
  211. 'use strict';
  212.  
  213. if (window.top !== window.self) return;
  214. if (location.pathname == '/url') return;
  215. if (location.pathname.startsWith('/sorry/')) return;
  216. const plang = navigator.language; // Preferred language // 首选语言
  217. const slang = 'en-US'; // Second language // 第二语言
  218. const is_zh = ['ZH', 'ZH-CN'].includes(plang.toUpperCase());
  219. const o_url = new URL(location);
  220. let url = new URL(location);
  221. let pfull = plang;
  222. let region = 'AUTO'; // Current Region // 当前区域
  223. if (plang.length == 5 && plang[2] == '-') {
  224. region = plang.slice(-2).toUpperCase();
  225. url.searchParams.set("gl", region);
  226. } else {
  227. pfull = plang + '-' + region;
  228. url.searchParams.delete("gl");
  229. }
  230. url.searchParams.set("hl", plang);
  231. url.searchParams.delete("client");
  232. const default_domain = 'google.com';
  233. const current_domian = location.hostname.match(/google\.[^\/]+/)?.[0];
  234. if (current_domian && current_domian != default_domain) {
  235. if (navigator.cookieEnabled) {
  236. url.hostname = location.hostname.replace(current_domian, default_domain);
  237. url.href = 'https://www.google.com/ncr#ncr:' + encodeURIComponent(url);
  238. window.stop();
  239. location.replace(url);
  240. return;
  241. } else {
  242. if (is_zh) {
  243. alert('[ACT.谷歌.DM.NCR]:\nCookie 已禁用,NCR 功能将不会生效。请检查浏览器设置。');
  244. } else {
  245. alert('[ACT.Google.DM.NCR]:\nCookies disabled, the NCR feature will not be active. Please check the browser settings.');
  246. }
  247. }
  248. }
  249. if (o_url.hash.slice(0, 5) == '#ncr:') {
  250. location.hash = '';
  251. window.stop();
  252. location.replace(decodeURIComponent(o_url.hash.slice(5)));
  253. return;
  254. }
  255.  
  256. const r1 = region;
  257. const r2 = region == slang.toUpperCase().slice(-2) ? 'AUTO' : slang.slice(-2);
  258. const l1 = plang;
  259. const l2 = plang.toUpperCase() == slang.toUpperCase() ? 'AUTO' : slang;
  260. const langbar = document.createElement('div');
  261. const langbar_ = document.createElement('div');
  262. const langbar_r = document.createElement('div');
  263. const langbar_r_r1 = document.createElement('span');
  264. const langbar_r_r2 = document.createElement('span');
  265. const langbar_l = document.createElement('div');
  266. const langbar_l_l1 = document.createElement('span');
  267. const langbar_l_l2 = document.createElement('span');
  268. const langbar_s = document.createElement('div');
  269. const langbar_s_t = document.createElement('span');
  270. langbar.className = 'act_langbar appbar mnr-c';
  271. langbar_.className = 'card-section mnr-c';
  272. langbar_r.textContent = is_zh ? '区域:' : 'REGION:';
  273. langbar_l.textContent = is_zh ? '语言:' : 'LANGUAGE:';
  274. langbar_s.textContent = is_zh ? '区域&语言:' : 'R&L:';
  275. langbar_r_r1.textContent = r1.toUpperCase();
  276. langbar_r_r2.textContent = r2.toUpperCase();
  277. langbar_l_l1.textContent = l1.toUpperCase();
  278. langbar_l_l2.textContent = l2.toUpperCase();
  279. langbar_r.append(langbar_r_r1, langbar_r_r2);
  280. langbar_l.append(langbar_l_l1, langbar_l_l2);
  281. langbar_s.append(langbar_s_t);
  282. langbar_.append(langbar_r, langbar_l, langbar_s);
  283. langbar.append(langbar_);
  284. let gl = r1, hl = plang, ss = 0;
  285. const ogl = o_url.searchParams.get("gl");
  286. const ohl = o_url.searchParams.get("hl");
  287. const safe_echo = s => (s.match(/^[a-zA-Z]{2}(?:-[a-zA-Z]{2})?$/)?.[0] || 'N/A').toUpperCase();;
  288. switch (ogl?.toUpperCase()) { // Region
  289. case r1.toUpperCase(): langbar_r_r1.className = 'act'; gl = r2; break;
  290. case r2.toUpperCase(): langbar_r_r2.className = 'act'; gl = r1; break;
  291. case undefined: r1 == 'AUTO' ? (langbar_r_r1.className = 'act', gl = r2) : (langbar_r_r2.className = 'act', langbar_r_r2.textContent = 'AUTO', ss++); break;
  292. default: langbar_r_r2.className = 'act'; langbar_r_r2.textContent = safe_echo(ogl); ss++;
  293. }
  294. switch (ohl?.toUpperCase()) { // Language
  295. case plang.toUpperCase(): langbar_l_l1.className = 'act'; hl = l2; langbar_s_t.textContent = slang.toUpperCase(); break;
  296. case slang.toUpperCase(): langbar_l_l2.className = 'act'; hl = l1; langbar_s_t.textContent = pfull.toUpperCase(); break;
  297. case undefined: langbar_l_l2.className = 'act'; langbar_l_l2.textContent = 'AUTO'; ss++; break;
  298. default: langbar_l_l2.className = 'act'; langbar_l_l2.textContent = safe_echo(ohl); ss++;
  299. }
  300. let sgl = gl, shl = hl;
  301. if ([r2, l2].includes('AUTO')) {
  302. ss > 1 && (sgl = r1, shl = l1, langbar_s_t.textContent = l1.toUpperCase());
  303. ss < 2 && langbar_s.remove();
  304. } else {
  305. ss && (sgl = r2, shl = l2, langbar_s_t.textContent = l2.toUpperCase());
  306. ss || hl.endsWith(gl) || langbar_s.remove();
  307. }
  308. url = new URL(location);
  309. langbar_r.addEventListener('click', event => {
  310. gl == 'AUTO' ? url.searchParams.delete("gl") : url.searchParams.set("gl", gl);
  311. location.replace(url);
  312. }, true);
  313. langbar_l.addEventListener('click', event => {
  314. if (langbar_l_l2.textContent === '') return;
  315. hl == 'AUTO' ? url.searchParams.delete("hl") : url.searchParams.set("hl", hl);
  316. location.replace(url);
  317. }, true);
  318. langbar_s.addEventListener('click', event => {
  319. sgl == 'AUTO' ? url.searchParams.delete("gl") : url.searchParams.set("gl", sgl);
  320. shl == 'AUTO' ? url.searchParams.delete("hl") : url.searchParams.set("hl", shl);
  321. location.replace(url);
  322. }, true);
  323. const langbar_style = document.createElement('style');
  324. langbar_style.textContent = `
  325. .act_langbar {
  326. line-height: 2;
  327. margin-bottom: 6px;
  328. user-select: none;
  329. -webkit-user-select: none;
  330. }
  331. .act_langbar>div {
  332. white-space: nowrap;
  333. overflow-x: scroll !important;
  334. scrollbar-width: none;
  335. mask-image: linear-gradient(to left, transparent, red 25px);
  336. }
  337. .act_langbar>div::-webkit-scrollbar { display: none; }
  338. .act_langbar>div>div {
  339. display: inline-block;
  340. padding: 0px 10px;
  341. margin-block: 3px;
  342. margin-inline: 0 15px;
  343. border: 1.5px solid;
  344. border-radius: 20px;
  345. cursor: pointer;
  346. }
  347. .act_langbar span {
  348. margin-left: 10px;
  349. }
  350. .act_langbar span.act {
  351. padding: 1px 5px;
  352. border: 1px solid;
  353. border-radius: 20px;
  354. }
  355. `;
  356.  
  357. if (document.head) {
  358. document.head.append(langbar_style);
  359. } else {
  360. new MutationObserver((mutationList, observer) => {
  361. document.head && (observer.disconnect(), document.head.append(langbar_style));
  362. }).observe(document, { subtree: true, childList: true });
  363. }
  364.  
  365. if (document.querySelector('#appbar')) {
  366. document.querySelector('#appbar')?.after(langbar);
  367. } else {
  368. new MutationObserver((mutationList, observer) => {
  369. document.querySelector('#appbar') && (observer.disconnect(), document.querySelector('#appbar')?.after(langbar));
  370. document.readyState == "complete" && observer.disconnect();
  371. }).observe(document, { subtree: true, childList: true });
  372. }
  373.  
  374. })();

QingJ © 2025

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