Google to YouTube Search

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name               Google to YouTube Search
// @namespace          https://greasyfork.org/en/users/10118-drhouse
// @version            6.8
// @description        Use your Google Search terms to search YouTube by clicking a new YouTube link added to your Google Search page.
// @include            https://www.google.*/search*
// @include            https://potato.net/*
// @require            http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @require            https://greasyfork.org/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=" R1QWuf" id="above" href="' + url + encodeURIComponent(query) + '"><div class="YmvwI mXwfNd mVH5Fc">' + site + '</div></a>')
            // .insertBefore("#uddia_1")
        // #hdtb-sc > div > div > div.crJ18e
        .insertAfter("#hdtb-tls").last();
    }
    
    var gquery = $("textarea").text()
    // const elementLength = $("#cnt > div:nth-child(8)").length;
    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);
    }
    
});