sammyangel99 / YouHook

// ==UserScript==
// @name         YouHook
// @namespace    youhook
// @version      1.1
// @description  Redirects external YouTube search and watch requests to HookTube
// @author       miroslavets90
// @license      MIT
// @include      *youtube.com/*
// @include      *youtube.com/*
// @include      *hooktube.com/*
// @include      *hooktube.com/*
// @grant        GM_addStyle
// @run-at       document-start
// ==/UserScript==

let url      = window.location.href;
let youtube  = (url.indexOf("youtube") !== -1);
let hooktube = (url.indexOf("hooktube") !== -1);
let search   = (url.indexOf("?search_query") !== -1);
let watch    = (url.indexOf("watch?") !== -1);
let referred = (url.indexOf("youhook=0") !== -1);

if (youtube && (search || watch) && !referred) {
    window.location.href = url.replace("you", "hook");
} else if (hooktube && watch) {
    window.onload = function() {
        GM_addStyle(".btn-youhook{background-color:#e52d27;border-color:#e52d27;margin-left:4px;}.btn-youhook:hover{background-color:#e11913;border-color:#e11913}.btn-youhook:focus{box-shadow:0 0 0 3px rgba(229,45,39,0.5);}");
        let ytlink = document.createElement("a");
        let dlmenu = document.getElementById("download-menu");
        ytlink.href = (url.replace("hook", "you") + "&youhook=0");
        ytlink.innerHTML = "YouTube";
        ytlink.className = "btn btn-success mb-2 btn-youhook";
        dlmenu.parentNode.insertBefore(ytlink, dlmenu.nextSibling);
    };
}