deltaDelete / YouTubeNewTabSearch

// ==UserScript==
// @name         YouTubeNewTabSearch
// @namespace    https://openuserjs.org/users/deltaDelete
// @include      https://www.youtube.com/*
// @version      0.5
// @description  Open search in new tab
// @author       deltaDelete
// @copyright 2020, deltaDelete (https://openuserjs.org/users/deltaDelete)
// @license MIT
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant        GM_addStyle
// @grant    GM_openInTab
// @grant        window.focus
// @run-at       document-idle
// ==/UserScript==

var isExecuted;
var styles = '<style>\
#new-tab-search:hover {\
    color: rgb(51 51 51 / 85%);\
}\
#new-tab-search {\
    color: var(--yt-spec-text-primary);\
    width: 64px;\
    height: inherit;\
    font-weight: 100;\
    cursor: pointer;\
    user-select: none;\
    display: flex;\
    justify-self: left;\
    justify-content: center;\
    align-items: center;\
}\
#search-icon-legacy.ytd-searchbox {\
    border-radius: 0;\
}\
</style>';
$("head").append('<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">');
$("head").append(styles);
waitForKeyElements("#search-icon-legacy", () => {
    onPageLoad()
    });
function newTabSearch() {
    var searchQuery = $('input#search').val().replace(/ /g,"+");;
    console.log(searchQuery+' is okay');
    window.open('https://www.youtube.com/results?search_query='+searchQuery, '_blank');
}
function onPageLoad() {
    $('<a id="new-tab-search" class="style-scope ytd-searchbox"><span class="material-icons">open_in_new</span></a>').insertAfter("#search-icon-legacy");
    $('#new-tab-search').click(newTabSearch);
}

function KeyPress(e) {
    var evtoobj = window.event? event : e
    if (evtoobj.ctrlKey && evtoobj.keyCode == 190) {
        newTabSearch();
    }
}
document.onkeydown = KeyPress;