Google to YouTube Search

Use your Google Search terms to search YouTube by clicking a new YouTube link added to your Google Search page.

As of 2023-12-17. See the latest version.

// ==UserScript==
// @name               Google to YouTube Search
// @namespace          https://greatest.deepsurf.us/en/users/10118-drhouse
// @version            6.3
// @description        Use your Google Search terms to search YouTube by clicking a new YouTube link added to your Google Search page.
// @run-at             document-start
// @include            https://www.google.*/search*
// @require            http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @require            https://greatest.deepsurf.us/scripts/439099-monkeyconfig-modern-reloaded/code/MonkeyConfig%20Modern%20Reloaded.js?version=1012538
// @grant              GM_getValue
// @grant              GM_setValue
// @grant              GM_addStyle
// @grant              GM_info
// @grant              GM_registerMenuCommand
// @author             drhouse
// @license            CC-BY-NC-SA-4.0
// @icon               https://www.google.com/s2/favicons?domain=google.com
// ==/UserScript==
/* global jQuery, MonkeyConfig, $ */
$(document).ready(function () {

    var cfg = new MonkeyConfig({
        title: 'Configure',
        menuCommand: true,
        params: {
            'YouTube': {
                type: 'checkbox',
                default: true
            },
            'Reddit': {
                type: 'checkbox',
                default: true
            },
            'Github': {
                type: 'checkbox',
                default: true
            },
        },
    })
    
    function createLink(site, url, query) {
        $('<a class="hdtb-mitem" id="above" href="' + url + encodeURIComponent(query) + '">&nbsp;&nbsp;<span class="bmaJhd iJddsb" style="height:16px;width:16px"><?xml version="1.0" ?><svg fill="currentColor" height="24" viewBox="-2 -3.5 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M3 .565h14a3 3 0 0 1 3 3v10a3 3 0 0 1-3 3H3a3 3 0 0 1-3-3v-10a3 3 0 0 1 3-3z"/></svg></span><div class="hdtb-mitem">' + site + '</span></div></a>')
            .insertAfter(".MUFPAc")
            .last();
    }

    var gquery = $("textarea").text()
    const elementLength = $("#cnt > div:nth-child(20)").length;
    const nthChildValue = elementLength === 1 ? 8 : 10;

    if (cfg.get('Github')) {
        createLink('Github', 'https://'+$(location).attr('hostname')+'/search?q=site%3Agithub.com+', gquery + '&type=repositories');
    }

    if (cfg.get('Reddit')) {
        createLink('Reddit', 'https://'+$(location).attr('hostname')+'/search?q=site%3Areddit.com+', gquery);
    }

    if (cfg.get('YouTube')) {
        createLink('YouTube', 'https://www.youtube.com/results?search_query=', gquery);
    }

});