├── LICENSE ├── README.md ├── screenshot.png └── userscript.js /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Mario O.M. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Reddit Search On Google 2 | A simple userscript that adds a button to your Google searches to show only Reddit posts. You can just click on the button and it will automatically add `site:reddit.com` to your search: 3 | 4 | ![Img](screenshot.png) 5 | 6 | ## Downloading the script 7 | The direct download link is here: 8 | 9 | * [GreasyFork](https://greasyfork.org/en/scripts/381497-reddit-search-on-google) 10 | 11 | **Chrome users:** you'll need a script manager extension like [TamperMonkey](https://addons.mozilla.org/en-US/firefox/addon/tampermonkey/) (the one I'm currently using) or [GreaseMonkey](https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/). Then go to the download link above and click on 'Install X.X'. Finally, click on 'install' in the new window that will open. 12 | 13 | **Firefox users:** you'll need a script manager extension like [TamperMonkey](https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=en). Then go to the download link above and click on 'Install X.X'. Finally, click on 'install' in the new window that will open. 14 | 15 | **Other browsers:** you can look for a script manager extension in your browser add-ons page. Look for Tampermonkey or Greasemonkey and install them. Then go to the download link above and click on 'Install X.X'. Finally, click on 'install' in the new window that will open. 16 | 17 | ## Customizing the script 18 | There are a couple things you can change inside the script: 19 | 20 | * `useIcon` can be set to `false` if you don't want to see an icon inside the Reddit button. By default it's set to `true` 21 | * `appendRight` can be set to `true` if you want to append the Reddit button to the right of Google's buttons (next to 'Tools'). By default it's set to `false`, which appends it next to the usual buttons like 'Videos'. 22 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marioortizmanero/reddit-search-on-google/cc783c34c74e92268e357f79affaea4e6814f25c/screenshot.png -------------------------------------------------------------------------------- /userscript.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name Reddit search on Google 3 | // @version 1.3.4 4 | // @description Adds a button to search Reddit posts with Google 5 | // @author Mario O.M. 6 | // @namespace https://github.com/marioortizmanero/reddit-search-on-google/ 7 | // @include http*://www.google.*/search* 8 | // @include http*://google.*/search* 9 | // @run-at document-end 10 | // ==/UserScript== 11 | 12 | // Change this to false if you don't want an icon 13 | const useIcon = true; 14 | // Change this to true if you want to add the button to the right of the 'Tools' button 15 | const appendRight = false; 16 | 17 | const queryRegex = /q=[^&]+/g; 18 | const siteRegex = /\+site(?:%3A|\:).+\.[^&+]+/g; 19 | const redditUrl = '+site%3Areddit.com'; 20 | let redditIcon = ''; 21 | const isImageSearch = /[?&]tbm=isch/.test(location.search); 22 | 23 | if (typeof trustedTypes !== 'undefined') { 24 | const policy = trustedTypes.createPolicy('html', { createHTML: input => input }); 25 | redditIcon = policy.createHTML(redditIcon); 26 | } 27 | 28 | (function () { 29 | // Creating the element 30 | let el = document.createElement('div'); 31 | el.className = 'hdtb-mitem'; 32 | const link = document.createElement('a'); 33 | 34 | // Adding the svg icon 35 | if (useIcon) { 36 | const span = document.createElement('span'); 37 | span.className = isImageSearch ? 'm3kSL' : 'bmaJhd iJddsb'; 38 | span.style.cssText = 'height:16px;width:16px'; 39 | span.innerHTML = redditIcon; 40 | link.appendChild(span); 41 | } 42 | 43 | // Hyperlink to add 'site:reddit.com' to the query 44 | link.appendChild(document.createTextNode('Reddit')); 45 | link.href = window.location.href.replace(queryRegex, (match) => { 46 | // Replaces the existing `site` flags 47 | return match.search(siteRegex) >= 0 ? match.replace(siteRegex, redditUrl) : match + redditUrl; 48 | }); 49 | if (isImageSearch) { 50 | link.classList.add('NZmxZe'); 51 | el = link; 52 | } else { 53 | el.appendChild(link); 54 | } 55 | 56 | // Inserting the element into Google search 57 | if (appendRight) { 58 | const toolsBtn = document.querySelector(isImageSearch ? '.ssfWCe' : '.t2vtad'); 59 | toolsBtn.parentNode.insertBefore(el, toolsBtn.nextSibling); 60 | } else { 61 | const menuBar = document.querySelector(isImageSearch ? '.T47uwc' : '.MUFPAc'); 62 | if (isImageSearch) { 63 | menuBar.insertBefore(el, menuBar.children[menuBar.childElementCount - 1]); 64 | } else { 65 | menuBar.appendChild(el); 66 | } 67 | } 68 | })(); 69 | --------------------------------------------------------------------------------