Greasy Fork is available in English.

Github search on Google

Adds a button to search github.com with Google

< Commentaires sur Github search on Google

Question / commentaire

§
Posté le: 2023-10-30

this thang broken, but not to fear

i do right by the people,

please implement:

const useIcon = true;
// Change this to true if you want to add the button to the right of the 'Tools' button
const appendRight = false;

const queryRegex = /q=[^&]+/g;
const siteRegex = /\+site(?:%3A|\:).+\.[^&+]+/g;
const githubUrl = '+site%3Agithub.com';
// Edit icon SVG < change path only
let githubIcon = '<svg foscusable="false" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path d="M8 0.25C3.58 0.25 0 3.80585 0 8.19603C0 11.7121 2.29 14.682 5.47 15.7348C5.87 15.8043 6.02 15.566 6.02 15.3574C6.02 15.1687 6.01 14.5429 6.01 13.8774C4 14.2449 3.48 13.3907 3.32 12.9438C3.23 12.7153 2.84 12.0101 2.5 11.8214C2.22 11.6724 1.82 11.3049 2.49 11.295C3.12 11.285 3.57 11.8711 3.72 12.1094C4.44 13.3113 5.59 12.9736 6.05 12.765C6.12 12.2485 6.33 11.9009 6.56 11.7022C4.78 11.5036 2.92 10.8182 2.92 7.77886C2.92 6.91473 3.23 6.19959 3.74 5.64337C3.66 5.44472 3.38 4.63025 3.82 3.53767C3.82 3.53767 4.49 3.32909 6.02 4.35214C6.66 4.17335 7.34 4.08396 8.02 4.08396C8.7 4.08396 9.38 4.17335 10.02 4.35214C11.55 3.31915 12.22 3.53767 12.22 3.53767C12.66 4.63025 12.38 5.44472 12.3 5.64337C12.81 6.19959 13.12 6.9048 13.12 7.77886C13.12 10.8281 11.25 11.5036 9.47 11.7022C9.76 11.9505 10.01 12.4273 10.01 13.1722C10.01 14.235 10 15.0892 10 15.3574C10 15.566 10.15 15.8143 10.55 15.7348C13.71 14.682 16 11.7022 16 8.19603C16 3.80585 12.42 0.25 8 0.25Z"/></svg>';
const isImageSearch = /[?&]tbm=isch/.test(location.search);

if (typeof trustedTypes !== 'undefined') {
    const policy = trustedTypes.createPolicy('html', { createHTML: input => input });
    githubIcon = policy.createHTML(githubIcon);
}

(function () {
    // Creating the element
    let el = document.createElement('div');
    el.className = 'hdtb-mitem';
    const link = document.createElement('a');

    // Adding the svg icon
    if (useIcon) {
        const span = document.createElement('span');
        span.className = isImageSearch ? 'm3kSL' : 'bmaJhd iJddsb';
        span.style.cssText = 'height:16px;width:16px';
        span.innerHTML = githubIcon;
        link.appendChild(span);
    }

    // Hyperlink to add 'site:github.com' to the query
    link.appendChild(document.createTextNode('Github'));
    link.href = window.location.href.replace(queryRegex, (match) => {
        // Replaces the existing `site` flags
        return match.search(siteRegex) >= 0 ? match.replace(siteRegex, githubUrl) : match + githubUrl;
    });
    if (isImageSearch) {
        link.classList.add('NZmxZe');
        el = link;
    } else {
        el.appendChild(link);
    }

    // Inserting the element into Google search
    if (appendRight) {
        const toolsBtn = document.querySelector(isImageSearch ? '.ssfWCe' : '.t2vtad');
        toolsBtn.parentNode.insertBefore(el, toolsBtn.nextSibling);
    } else {
        const menuBar = document.querySelector(isImageSearch ? '.T47uwc' : '.MUFPAc');
        if (isImageSearch) {
            menuBar.insertBefore(el, menuBar.children[menuBar.childElementCount - 1]);
        } else {
            menuBar.appendChild(el);
        }
    }
})();
AlexyoeAuteur
§
Posté le: 2023-12-07

What in the script doesn't seem to be working for you? This script is still working fine from all of my tests. If you want to submit a issue on Github I'd be happy to take a look.

Poster une réponse

Connectez-vous pour poster une réponse.