Google搜尋顯示桌面版網站

把 google 搜尋結果的行動裝置版網站取代為桌面版網站

  1. // ==UserScript==
  2. // @name Google搜尋顯示桌面版網站
  3. // @name:en Desktop Website for Google Search
  4. // @name:zh-TW Google搜尋顯示桌面版網站
  5. // @namespace https://github.com/rod24574575
  6. // @description 把 google 搜尋結果的行動裝置版網站取代為桌面版網站
  7. // @description:en Replace the google search result from mobile to desktop website.
  8. // @description:zh-TW 把 google 搜尋結果的行動裝置版網站取代為桌面版網站
  9. // @version 1.0.3
  10. // @license MIT
  11. // @author rod24574575
  12. // @homepage https://github.com/rod24574575/monorepo
  13. // @homepageURL https://github.com/rod24574575/monorepo
  14. // @supportURL https://github.com/rod24574575/monorepo/issues
  15. // @match *://*.google.com/search*
  16. // @match *://*.google.ad/search*
  17. // @match *://*.google.ae/search*
  18. // @match *://*.google.com.af/search*
  19. // @match *://*.google.com.ag/search*
  20. // @match *://*.google.al/search*
  21. // @match *://*.google.am/search*
  22. // @match *://*.google.co.ao/search*
  23. // @match *://*.google.com.ar/search*
  24. // @match *://*.google.as/search*
  25. // @match *://*.google.at/search*
  26. // @match *://*.google.com.au/search*
  27. // @match *://*.google.az/search*
  28. // @match *://*.google.ba/search*
  29. // @match *://*.google.com.bd/search*
  30. // @match *://*.google.be/search*
  31. // @match *://*.google.bf/search*
  32. // @match *://*.google.bg/search*
  33. // @match *://*.google.com.bh/search*
  34. // @match *://*.google.bi/search*
  35. // @match *://*.google.bj/search*
  36. // @match *://*.google.com.bn/search*
  37. // @match *://*.google.com.bo/search*
  38. // @match *://*.google.com.br/search*
  39. // @match *://*.google.bs/search*
  40. // @match *://*.google.bt/search*
  41. // @match *://*.google.co.bw/search*
  42. // @match *://*.google.by/search*
  43. // @match *://*.google.com.bz/search*
  44. // @match *://*.google.ca/search*
  45. // @match *://*.google.cd/search*
  46. // @match *://*.google.cf/search*
  47. // @match *://*.google.cg/search*
  48. // @match *://*.google.ch/search*
  49. // @match *://*.google.ci/search*
  50. // @match *://*.google.co.ck/search*
  51. // @match *://*.google.cl/search*
  52. // @match *://*.google.cm/search*
  53. // @match *://*.google.cn/search*
  54. // @match *://*.google.com.co/search*
  55. // @match *://*.google.co.cr/search*
  56. // @match *://*.google.com.cu/search*
  57. // @match *://*.google.cv/search*
  58. // @match *://*.google.com.cy/search*
  59. // @match *://*.google.cz/search*
  60. // @match *://*.google.de/search*
  61. // @match *://*.google.dj/search*
  62. // @match *://*.google.dk/search*
  63. // @match *://*.google.dm/search*
  64. // @match *://*.google.com.do/search*
  65. // @match *://*.google.dz/search*
  66. // @match *://*.google.com.ec/search*
  67. // @match *://*.google.ee/search*
  68. // @match *://*.google.com.eg/search*
  69. // @match *://*.google.es/search*
  70. // @match *://*.google.com.et/search*
  71. // @match *://*.google.fi/search*
  72. // @match *://*.google.com.fj/search*
  73. // @match *://*.google.fm/search*
  74. // @match *://*.google.fr/search*
  75. // @match *://*.google.ga/search*
  76. // @match *://*.google.ge/search*
  77. // @match *://*.google.gg/search*
  78. // @match *://*.google.com.gh/search*
  79. // @match *://*.google.com.gi/search*
  80. // @match *://*.google.gl/search*
  81. // @match *://*.google.gm/search*
  82. // @match *://*.google.gr/search*
  83. // @match *://*.google.com.gt/search*
  84. // @match *://*.google.gy/search*
  85. // @match *://*.google.com.hk/search*
  86. // @match *://*.google.hn/search*
  87. // @match *://*.google.hr/search*
  88. // @match *://*.google.ht/search*
  89. // @match *://*.google.hu/search*
  90. // @match *://*.google.co.id/search*
  91. // @match *://*.google.ie/search*
  92. // @match *://*.google.co.il/search*
  93. // @match *://*.google.im/search*
  94. // @match *://*.google.co.in/search*
  95. // @match *://*.google.iq/search*
  96. // @match *://*.google.is/search*
  97. // @match *://*.google.it/search*
  98. // @match *://*.google.je/search*
  99. // @match *://*.google.com.jm/search*
  100. // @match *://*.google.jo/search*
  101. // @match *://*.google.co.jp/search*
  102. // @match *://*.google.co.ke/search*
  103. // @match *://*.google.com.kh/search*
  104. // @match *://*.google.ki/search*
  105. // @match *://*.google.kg/search*
  106. // @match *://*.google.co.kr/search*
  107. // @match *://*.google.com.kw/search*
  108. // @match *://*.google.kz/search*
  109. // @match *://*.google.la/search*
  110. // @match *://*.google.com.lb/search*
  111. // @match *://*.google.li/search*
  112. // @match *://*.google.lk/search*
  113. // @match *://*.google.co.ls/search*
  114. // @match *://*.google.lt/search*
  115. // @match *://*.google.lu/search*
  116. // @match *://*.google.lv/search*
  117. // @match *://*.google.com.ly/search*
  118. // @match *://*.google.co.ma/search*
  119. // @match *://*.google.md/search*
  120. // @match *://*.google.me/search*
  121. // @match *://*.google.mg/search*
  122. // @match *://*.google.mk/search*
  123. // @match *://*.google.ml/search*
  124. // @match *://*.google.com.mm/search*
  125. // @match *://*.google.mn/search*
  126. // @match *://*.google.com.mt/search*
  127. // @match *://*.google.mu/search*
  128. // @match *://*.google.mv/search*
  129. // @match *://*.google.mw/search*
  130. // @match *://*.google.com.mx/search*
  131. // @match *://*.google.com.my/search*
  132. // @match *://*.google.co.mz/search*
  133. // @match *://*.google.com.na/search*
  134. // @match *://*.google.com.ng/search*
  135. // @match *://*.google.com.ni/search*
  136. // @match *://*.google.ne/search*
  137. // @match *://*.google.nl/search*
  138. // @match *://*.google.no/search*
  139. // @match *://*.google.com.np/search*
  140. // @match *://*.google.nr/search*
  141. // @match *://*.google.nu/search*
  142. // @match *://*.google.co.nz/search*
  143. // @match *://*.google.com.om/search*
  144. // @match *://*.google.com.pa/search*
  145. // @match *://*.google.com.pe/search*
  146. // @match *://*.google.com.pg/search*
  147. // @match *://*.google.com.ph/search*
  148. // @match *://*.google.com.pk/search*
  149. // @match *://*.google.pl/search*
  150. // @match *://*.google.pn/search*
  151. // @match *://*.google.com.pr/search*
  152. // @match *://*.google.ps/search*
  153. // @match *://*.google.pt/search*
  154. // @match *://*.google.com.py/search*
  155. // @match *://*.google.com.qa/search*
  156. // @match *://*.google.ro/search*
  157. // @match *://*.google.ru/search*
  158. // @match *://*.google.rw/search*
  159. // @match *://*.google.com.sa/search*
  160. // @match *://*.google.com.sb/search*
  161. // @match *://*.google.sc/search*
  162. // @match *://*.google.se/search*
  163. // @match *://*.google.com.sg/search*
  164. // @match *://*.google.sh/search*
  165. // @match *://*.google.si/search*
  166. // @match *://*.google.sk/search*
  167. // @match *://*.google.com.sl/search*
  168. // @match *://*.google.sn/search*
  169. // @match *://*.google.so/search*
  170. // @match *://*.google.sm/search*
  171. // @match *://*.google.sr/search*
  172. // @match *://*.google.st/search*
  173. // @match *://*.google.com.sv/search*
  174. // @match *://*.google.td/search*
  175. // @match *://*.google.tg/search*
  176. // @match *://*.google.co.th/search*
  177. // @match *://*.google.com.tj/search*
  178. // @match *://*.google.tl/search*
  179. // @match *://*.google.tm/search*
  180. // @match *://*.google.tn/search*
  181. // @match *://*.google.to/search*
  182. // @match *://*.google.com.tr/search*
  183. // @match *://*.google.tt/search*
  184. // @match *://*.google.com.tw/search*
  185. // @match *://*.google.co.tz/search*
  186. // @match *://*.google.com.ua/search*
  187. // @match *://*.google.co.ug/search*
  188. // @match *://*.google.co.uk/search*
  189. // @match *://*.google.com.uy/search*
  190. // @match *://*.google.co.uz/search*
  191. // @match *://*.google.com.vc/search*
  192. // @match *://*.google.co.ve/search*
  193. // @match *://*.google.co.vi/search*
  194. // @match *://*.google.com.vn/search*
  195. // @match *://*.google.vu/search*
  196. // @match *://*.google.ws/search*
  197. // @match *://*.google.rs/search*
  198. // @match *://*.google.co.za/search*
  199. // @match *://*.google.co.zm/search*
  200. // @match *://*.google.co.zw/search*
  201. // @match *://*.google.cat/search*
  202. // @run-at document-idle
  203. // ==/UserScript==
  204.  
  205. // The google domains are from the following link:
  206. // https://www.google.com/supported_domains
  207.  
  208. // @ts-check
  209. 'use strict';
  210.  
  211. (function() {
  212. /**
  213. * @typedef {(url: string) => string | null} UrlTransformer
  214. */
  215.  
  216. /**
  217. * @typedef {UrlTransformer | [searcher: RegExp, replacer: string | ((url: string, matches: RegExpExecArray) => string)]} UrlTransformerLike
  218. */
  219.  
  220. /**
  221. * @param {UrlTransformerLike} transformerLike
  222. * @returns {UrlTransformer}
  223. */
  224. function ensureUrlTransformer(transformerLike) {
  225. if (typeof transformerLike === 'function') {
  226. return transformerLike;
  227. }
  228.  
  229. let [searcher, replacer] = transformerLike;
  230. if (typeof replacer === 'string') {
  231. const replacementString = replacer;
  232. replacer = (url, matches) => {
  233. return url.slice(0, matches.index) + replacementString + url.slice(matches.index + matches[0].length);
  234. };
  235. }
  236. return (url) => {
  237. const matches = searcher.exec(url);
  238. if (!matches) {
  239. return null;
  240. }
  241. return replacer(url, matches);
  242. };
  243. }
  244.  
  245. /** @type {Array<[urlTransformerLike: UrlTransformerLike, hostTransformerLike?: UrlTransformerLike]>} */
  246. const patterns = [
  247. [[/\.m\.wikipedia\.org/, '.wikipedia.org']],
  248. [
  249. [/m\d*\.momoshop\.com\.tw\/(main|goods|search|category)\.momo\b/, (url, matches) => {
  250. const target = matches.at(1);
  251.  
  252. const before = url.slice(0, matches.index);
  253. let replacement = 'www.momoshop.com.tw/';
  254. let after = url.slice(matches.index + matches[0].length);
  255.  
  256. if (target) {
  257. switch (target) {
  258. case 'main':
  259. replacement += 'main/Main.jsp';
  260. break;
  261. case 'goods':
  262. replacement += 'goods/GoodsDetail.jsp';
  263. break;
  264. case 'search':
  265. replacement += 'search/searchShop.jsp';
  266. after = after.replace('searchKeyword=', 'keyword=');
  267. break;
  268. case 'category':
  269. replacement += 'category/DgrpCategory.jsp';
  270. after = after.replace('cn=', 'd_code=');
  271. break;
  272. default:
  273. break;
  274. }
  275. }
  276.  
  277. return before + replacement + after;
  278. }],
  279. [/m\d*\.momoshop\.com\.tw/, 'www.momoshop.com.tw'],
  280. ],
  281. ];
  282.  
  283. /** @type {ReadonlyArray<[urlTransformer: UrlTransformer, hostTransformer: UrlTransformer]>} */
  284. const transformers = patterns.map(([urlTransformerLike, hostTransformerLike]) => {
  285. const urlTransformer = ensureUrlTransformer(urlTransformerLike);
  286. const hostTransformer = hostTransformerLike ? ensureUrlTransformer(hostTransformerLike) : urlTransformer;
  287. return [urlTransformer, hostTransformer];
  288. });
  289.  
  290. /** @type {WeakSet<Element>} */
  291. const cacheSet = new WeakSet();
  292.  
  293. function run() {
  294. for (const anchorElement of /** @type {NodeListOf<HTMLAnchorElement>} */ (document.querySelectorAll('a[href][data-ved]:has(> h3):has(> div.notranslate)'))) {
  295. if (cacheSet.has(anchorElement)) {
  296. continue;
  297. }
  298. cacheSet.add(anchorElement);
  299.  
  300. for (const [urlTransformer, hostTransformer] of transformers) {
  301. const href = urlTransformer(anchorElement.href);
  302. if (href == null) {
  303. continue;
  304. }
  305.  
  306. anchorElement.href = href;
  307.  
  308. // Only for chrome.
  309. const pingAttribute = anchorElement.getAttribute('ping');
  310. if (pingAttribute) {
  311. const result = urlTransformer(decodeURIComponent(pingAttribute));
  312. if (result != null) {
  313. anchorElement.setAttribute('ping', encodeURIComponent(result));
  314. }
  315. }
  316.  
  317. const anchorCiteChild = anchorElement.querySelector('cite')?.firstChild;
  318. if (anchorCiteChild && anchorCiteChild.nodeType === anchorCiteChild.TEXT_NODE) {
  319. const citeText = /** @type {Text} */ (anchorCiteChild);
  320. const result = hostTransformer(citeText.data);
  321. if (result != null) {
  322. citeText.data = result;
  323. }
  324. }
  325.  
  326. const infoCiteChild = anchorElement.parentElement?.nextElementSibling?.querySelector('cite')?.firstChild;
  327. if (infoCiteChild && infoCiteChild.nodeType === infoCiteChild.TEXT_NODE) {
  328. const citeText = /** @type {Text} */ (infoCiteChild);
  329. const result = hostTransformer(citeText.data);
  330. if (result != null) {
  331. citeText.data = result;
  332. }
  333. }
  334.  
  335. // Bypass google's link redirection warning.
  336. anchorElement.removeAttribute('data-jsarwt');
  337. break;
  338. }
  339. }
  340. }
  341.  
  342. function main() {
  343. const mutationObserver = new MutationObserver(run);
  344. mutationObserver.observe(document.body, { childList: true, subtree: true });
  345. run();
  346. }
  347.  
  348. main();
  349. })();

QingJ © 2025

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