// ==UserScript== // @name Reddit on Google Search // @version 1.1.1 // @description Adds a button to search Reddit via Google Search // @author Alexyoe // @namespace https://github.com/Alexyoe/Reddit-on-Google-Search // @license MIT // @include http*://www.google.*/search* // @include http*://google.*/search* // @run-at document-end // @downloadURL https://update.greasyfork.icu/scripts/462356/Reddit%20on%20Google%20Search.user.js // @updateURL https://update.greasyfork.icu/scripts/462356/Reddit%20on%20Google%20Search.meta.js // ==/UserScript== const settings = { // Choose exactly one: "icon" or "label" displayMode: "icon", btnPosition: "start", // "start", "end", or "afterai" fixSize: false, }; // Start Code const queryRegex = /q=[^&]+/g; const siteRegex = /\+site(?:%3A|\:).+\.[^&+]+/g; const redditUrl = "+site%3Areddit.com"; // Reddit SVG let redditIcon = ` `; // Trusted Types for CSP if (typeof trustedTypes !== "undefined") { const p = trustedTypes.createPolicy("html", { createHTML: (x) => x }); redditIcon = p.createHTML(redditIcon); } (function waitForNav() { const nav = Array.from( document.querySelectorAll('div[role="navigation"]') ).find((n) => n.querySelector('div[role="listitem"] a')); if (!nav) return setTimeout(waitForNav, 200); // 1) grab the first wrapper