Site search on Google

Adds a button to search results under specific websites with Google

  1. // ==UserScript==
  2. // @name Site search on Google
  3. // @version 1.0.1.3
  4. // @license MIT
  5. // @description Adds a button to search results under specific websites with Google
  6. // @author IcyBearLovesSleep
  7. // @namespace https://github.com/IcyBearLovesSleep/reddit-search-on-google-2
  8. // @match https://*.google.com/search*
  9. // @match https://*.google.ad/search*
  10. // @match https://*.google.ae/search*
  11. // @match https://*.google.com.af/search*
  12. // @match https://*.google.com.ag/search*
  13. // @match https://*.google.com.ai/search*
  14. // @match https://*.google.al/search*
  15. // @match https://*.google.am/search*
  16. // @match https://*.google.co.ao/search*
  17. // @match https://*.google.com.ar/search*
  18. // @match https://*.google.as/search*
  19. // @match https://*.google.at/search*
  20. // @match https://*.google.com.au/search*
  21. // @match https://*.google.az/search*
  22. // @match https://*.google.ba/search*
  23. // @match https://*.google.com.bd/search*
  24. // @match https://*.google.be/search*
  25. // @match https://*.google.bf/search*
  26. // @match https://*.google.bg/search*
  27. // @match https://*.google.com.bh/search*
  28. // @match https://*.google.bi/search*
  29. // @match https://*.google.bj/search*
  30. // @match https://*.google.com.bn/search*
  31. // @match https://*.google.com.bo/search*
  32. // @match https://*.google.com.br/search*
  33. // @match https://*.google.bs/search*
  34. // @match https://*.google.bt/search*
  35. // @match https://*.google.co.bw/search*
  36. // @match https://*.google.by/search*
  37. // @match https://*.google.com.bz/search*
  38. // @match https://*.google.ca/search*
  39. // @match https://*.google.cd/search*
  40. // @match https://*.google.cf/search*
  41. // @match https://*.google.cg/search*
  42. // @match https://*.google.ch/search*
  43. // @match https://*.google.ci/search*
  44. // @match https://*.google.co.ck/search*
  45. // @match https://*.google.cl/search*
  46. // @match https://*.google.cm/search*
  47. // @match https://*.google.cn/search*
  48. // @match https://*.google.com.co/search*
  49. // @match https://*.google.co.cr/search*
  50. // @match https://*.google.com.cu/search*
  51. // @match https://*.google.cv/search*
  52. // @match https://*.google.com.cy/search*
  53. // @match https://*.google.cz/search*
  54. // @match https://*.google.de/search*
  55. // @match https://*.google.dj/search*
  56. // @match https://*.google.dk/search*
  57. // @match https://*.google.dm/search*
  58. // @match https://*.google.com.do/search*
  59. // @match https://*.google.dz/search*
  60. // @match https://*.google.com.ec/search*
  61. // @match https://*.google.ee/search*
  62. // @match https://*.google.com.eg/search*
  63. // @match https://*.google.es/search*
  64. // @match https://*.google.com.et/search*
  65. // @match https://*.google.fi/search*
  66. // @match https://*.google.com.fj/search*
  67. // @match https://*.google.fm/search*
  68. // @match https://*.google.fr/search*
  69. // @match https://*.google.ga/search*
  70. // @match https://*.google.ge/search*
  71. // @match https://*.google.gg/search*
  72. // @match https://*.google.com.gh/search*
  73. // @match https://*.google.com.gi/search*
  74. // @match https://*.google.gl/search*
  75. // @match https://*.google.gm/search*
  76. // @match https://*.google.gr/search*
  77. // @match https://*.google.com.gt/search*
  78. // @match https://*.google.gy/search*
  79. // @match https://*.google.com.hk/search*
  80. // @match https://*.google.hn/search*
  81. // @match https://*.google.hr/search*
  82. // @match https://*.google.ht/search*
  83. // @match https://*.google.hu/search*
  84. // @match https://*.google.co.id/search*
  85. // @match https://*.google.ie/search*
  86. // @match https://*.google.co.il/search*
  87. // @match https://*.google.im/search*
  88. // @match https://*.google.co.in/search*
  89. // @match https://*.google.iq/search*
  90. // @match https://*.google.is/search*
  91. // @match https://*.google.it/search*
  92. // @match https://*.google.je/search*
  93. // @match https://*.google.com.jm/search*
  94. // @match https://*.google.jo/search*
  95. // @match https://*.google.co.jp/search*
  96. // @match https://*.google.co.ke/search*
  97. // @match https://*.google.com.kh/search*
  98. // @match https://*.google.ki/search*
  99. // @match https://*.google.kg/search*
  100. // @match https://*.google.co.kr/search*
  101. // @match https://*.google.com.kw/search*
  102. // @match https://*.google.kz/search*
  103. // @match https://*.google.la/search*
  104. // @match https://*.google.com.lb/search*
  105. // @match https://*.google.li/search*
  106. // @match https://*.google.lk/search*
  107. // @match https://*.google.co.ls/search*
  108. // @match https://*.google.lt/search*
  109. // @match https://*.google.lu/search*
  110. // @match https://*.google.lv/search*
  111. // @match https://*.google.com.ly/search*
  112. // @match https://*.google.co.ma/search*
  113. // @match https://*.google.md/search*
  114. // @match https://*.google.me/search*
  115. // @match https://*.google.mg/search*
  116. // @match https://*.google.mk/search*
  117. // @match https://*.google.ml/search*
  118. // @match https://*.google.com.mm/search*
  119. // @match https://*.google.mn/search*
  120. // @match https://*.google.ms/search*
  121. // @match https://*.google.com.mt/search*
  122. // @match https://*.google.mu/search*
  123. // @match https://*.google.mv/search*
  124. // @match https://*.google.mw/search*
  125. // @match https://*.google.com.mx/search*
  126. // @match https://*.google.com.my/search*
  127. // @match https://*.google.co.mz/search*
  128. // @match https://*.google.com.na/search*
  129. // @match https://*.google.com.ng/search*
  130. // @match https://*.google.com.ni/search*
  131. // @match https://*.google.ne/search*
  132. // @match https://*.google.nl/search*
  133. // @match https://*.google.no/search*
  134. // @match https://*.google.com.np/search*
  135. // @match https://*.google.nr/search*
  136. // @match https://*.google.nu/search*
  137. // @match https://*.google.co.nz/search*
  138. // @match https://*.google.com.om/search*
  139. // @match https://*.google.com.pa/search*
  140. // @match https://*.google.com.pe/search*
  141. // @match https://*.google.com.pg/search*
  142. // @match https://*.google.com.ph/search*
  143. // @match https://*.google.com.pk/search*
  144. // @match https://*.google.pl/search*
  145. // @match https://*.google.pn/search*
  146. // @match https://*.google.com.pr/search*
  147. // @match https://*.google.ps/search*
  148. // @match https://*.google.pt/search*
  149. // @match https://*.google.com.py/search*
  150. // @match https://*.google.com.qa/search*
  151. // @match https://*.google.ro/search*
  152. // @match https://*.google.ru/search*
  153. // @match https://*.google.rw/search*
  154. // @match https://*.google.com.sa/search*
  155. // @match https://*.google.com.sb/search*
  156. // @match https://*.google.sc/search*
  157. // @match https://*.google.se/search*
  158. // @match https://*.google.com.sg/search*
  159. // @match https://*.google.sh/search*
  160. // @match https://*.google.si/search*
  161. // @match https://*.google.sk/search*
  162. // @match https://*.google.com.sl/search*
  163. // @match https://*.google.sn/search*
  164. // @match https://*.google.so/search*
  165. // @match https://*.google.sm/search*
  166. // @match https://*.google.sr/search*
  167. // @match https://*.google.st/search*
  168. // @match https://*.google.com.sv/search*
  169. // @match https://*.google.td/search*
  170. // @match https://*.google.tg/search*
  171. // @match https://*.google.co.th/search*
  172. // @match https://*.google.com.tj/search*
  173. // @match https://*.google.tl/search*
  174. // @match https://*.google.tm/search*
  175. // @match https://*.google.tn/search*
  176. // @match https://*.google.to/search*
  177. // @match https://*.google.com.tr/search*
  178. // @match https://*.google.tt/search*
  179. // @match https://*.google.com.tw/search*
  180. // @match https://*.google.co.tz/search*
  181. // @match https://*.google.com.ua/search*
  182. // @match https://*.google.co.ug/search*
  183. // @match https://*.google.co.uk/search*
  184. // @match https://*.google.com.uy/search*
  185. // @match https://*.google.co.uz/search*
  186. // @match https://*.google.com.vc/search*
  187. // @match https://*.google.co.ve/search*
  188. // @match https://*.google.vg/search*
  189. // @match https://*.google.co.vi/search*
  190. // @match https://*.google.com.vn/search*
  191. // @match https://*.google.vu/search*
  192. // @match https://*.google.ws/search*
  193. // @match https://*.google.rs/search*
  194. // @match https://*.google.co.za/search*
  195. // @match https://*.google.co.zm/search*
  196. // @match https://*.google.co.zw/search*
  197. // @match https://*.google.cat/search*
  198. // @run-at document-end
  199. // ==/UserScript==
  200.  
  201. // put in desire site searches
  202. const siteData = [
  203. {
  204. site:"reddit.com",
  205. name:"Reddit"
  206. },
  207. {
  208. site:"youtube.com",
  209. name:"Youtube"
  210. },
  211. {
  212. site:"wikipedia.com",
  213. name:"Wikipedia"
  214. }
  215. ]
  216.  
  217. // Change this to false if you don't want an icon
  218. const useIcon = true;
  219. // Change this to true if you want to add the button to the right of the 'Tools' button
  220. const appendRight = false;
  221.  
  222. const queryRegex = /q=[^&]+/g;
  223. const siteRegex = /\+site(?:%3A|\:).+\.[^&+]+/g;
  224. let redditIcon = '<svg foscusable="false" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path d="M0 7.59c.1-.26.15-.54.28-.77.57-1 1.83-1.29 2.79-.67.09.06.15.06.24 0A8.94 8.94 0 017.5 5c.1 0 .15-.04.19-.14l1.17-3.32.05-.15 1.23.3c.56.12 1.12.25 1.68.4.1.02.15 0 .2-.09a1.66 1.66 0 013.06 1.02c-.06.8-.72 1.46-1.5 1.52-.85.06-1.6-.47-1.77-1.28-.04-.17-.1-.23-.27-.27L9.54 2.5l-.88 2.48c.37.05.72.08 1.07.14 1.05.17 2.04.5 2.96 1.04.09.05.14.05.23 0a1.99 1.99 0 012.34 3.2c-.04.04-.08.11-.08.17a3.67 3.67 0 01-.9 2.73 6.36 6.36 0 01-2.9 1.92c-2.47.86-4.93.8-7.35-.22a5.89 5.89 0 01-2.48-1.9A3.56 3.56 0 01.8 9.5c0-.04 0-.1-.03-.11a2.1 2.1 0 01-.76-1.32v-.01-.47zm7.72 6.22c1.5 0 2.67-.21 3.73-.66a5.2 5.2 0 002.15-1.54c.83-1.06.85-2.3.06-3.38-.4-.56-.93-.97-1.52-1.3a8.15 8.15 0 00-3.44-.97 9.04 9.04 0 00-4.17.63c-.83.35-1.58.82-2.15 1.54a2.66 2.66 0 00-.08 3.38c.41.57.95.99 1.55 1.32 1.29.7 2.68.97 3.87.98zm5.7-11.63a.7.7 0 00-.7.7c0 .39.32.7.7.71a.7.7 0 00.72-.72.7.7 0 00-.72-.7zm1.44 6.2a1 1 0 00-.05-1.22c-.29-.34-.79-.48-1.14-.3.49.43.9.92 1.19 1.53zM1.12 8.38c.3-.6.7-1.09 1.19-1.52-.35-.16-.81-.03-1.1.29-.3.33-.34.83-.09 1.23z"/><path d="M7.98 13.1a4.77 4.77 0 01-1.99-.45 3.58 3.58 0 01-.65-.45c-.24-.2-.24-.5-.04-.7.19-.2.47-.19.7.01.33.3.73.44 1.16.52.76.14 1.52.11 2.24-.17.24-.1.45-.24.66-.38.22-.16.5-.16.68.03.18.2.17.5-.04.68-.43.39-.95.62-1.5.73-.4.08-.81.12-1.22.18zM11.67 9.04a1.3 1.3 0 01-2.6 0 1.3 1.3 0 012.6 0zM4.46 9.04c0-.73.6-1.3 1.32-1.3a1.3 1.3 0 11-1.32 1.3z"/></svg>';
  225. const isImageSearch = /[?&]tbm=isch/.test(location.search);
  226.  
  227. if (typeof trustedTypes !== 'undefined') {
  228. const policy = trustedTypes.createPolicy('html', { createHTML: input => input });
  229. redditIcon = policy.createHTML(redditIcon);
  230. }
  231.  
  232. (function () {
  233. const elements = document.getElementsByClassName("MUFPAc");
  234.  
  235. if (elements.length > 0) {
  236. for (let i = 0; i < siteData.length; i++) {
  237. let Url = '+site%3A'+siteData[i].site;
  238.  
  239. // Creating the element
  240. let el = document.createElement('div');
  241. el.className = 'hdtb-mitem';
  242. const link = document.createElement('a');
  243. if(siteData[i].name=="Reddit"){
  244. // Adding the svg icon
  245. if (useIcon) {
  246. const span = document.createElement('span');
  247. span.className = isImageSearch ? 'm3kSL' : 'bmaJhd iJddsb';
  248. span.style.cssText = 'height:16px;width:16px';
  249. span.innerHTML = redditIcon;
  250. link.appendChild(span);
  251. }
  252. }
  253.  
  254. // Hyperlink to add 'site:reddit.com' to the query
  255. link.appendChild(document.createTextNode(siteData[i].name));
  256. link.href = window.location.href.replace(queryRegex, (match) => {
  257. // Replaces the existing `site` flags
  258. return match.search(siteRegex) >= 0 ? match.replace(siteRegex, Url) : match + Url;
  259. });
  260. if (isImageSearch) {
  261. link.classList.add('NZmxZe');
  262. el = link;
  263. } else {
  264. el.appendChild(link);
  265. }
  266.  
  267. // Inserting the element into Google search
  268. if (appendRight) {
  269. const toolsBtn = document.querySelector(isImageSearch ? '.ssfWCe' : '.t2vtad');
  270. toolsBtn.parentNode.insertBefore(el, toolsBtn.nextSibling);
  271. } else {
  272. const menuBar = document.querySelector(isImageSearch ? '.T47uwc' : '.MUFPAc');
  273. if (isImageSearch) {
  274. menuBar.insertBefore(el, menuBar.children[menuBar.childElementCount - 1]);
  275. } else {
  276. menuBar.appendChild(el);
  277. }
  278. }
  279. }
  280. }
  281. const elements2 = document.getElementsByClassName("MUFPAc");
  282.  
  283. if (elements2.length > 0) {
  284. for (let i = 0; i < siteData.length; i++) {
  285. let Url = '+site%3A'+siteData[i].site;
  286.  
  287. window.addEventListener("load", function () {
  288. const menu = document.querySelector('.nfdoRb')
  289. // creates button
  290. let button = document.createElement('a')
  291. button.className = 'zItAnd FOU1zf'
  292. button.href = window.location.href.replace(queryRegex, (match) => {
  293. // Replaces the existing `site` flags
  294. return match.search(siteRegex) >= 0 ? match.replace(siteRegex, Url) : match + Url;
  295. });
  296.  
  297. button.innerText = siteData[i].name
  298. document.querySelector('.nfdoRb').append(button)
  299. }, false)
  300. }
  301. }
  302. })();

QingJ © 2025

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