// ==UserScript== // @name Github search on Google // @version 2.1.0 // @description Adds a button to search github.com with Google // @author Alexyoe // @namespace https://github.com/Alexyoe/Github-on-Google-Search // @license MIT // @include http*://www.google.*/search* // @include http*://google.*/search* // @run-at document-end // @downloadURL https://update.greasyfork.icu/scripts/462358/Github%20search%20on%20Google.user.js // @updateURL https://update.greasyfork.icu/scripts/462358/Github%20search%20on%20Google.meta.js // ==/UserScript== // Settings 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 githubUrl = "+site%3Agithub.com"; // Github SVG let githubIcon = ''; const isImageSearch = /[?&]tbm=isch/.test(location.search); // Trusted Types for CSP if (typeof trustedTypes !== "undefined") { const p = trustedTypes.createPolicy("html", { createHTML: (x) => x }); githubIcon = p.createHTML(githubIcon); } // Main function to run on load. Waits for nav to load. (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); // Grab the first wrapper