nascent / 9Convert Youtube Download Button

// ==UserScript==
// @name        9Convert Youtube Download Button
// @namespace   https://9convert.com/
// @version     1.0
// @date        2019-07-23
// @author      A Koi, nascent
// @description 9Convert Downloader: Download Video and Audio for free
// @include     http://*youtube.com*
// @include     https://*youtube.com*
// @run-at      document-end
// @grant       none
// @connect     youtube.com
// @connect     m.youtube.com
// @connect     www.youtube.com
// @connect     youtube-nocookie.com
// @connect     youtu.be
// @connect     9convert.com
// @updateURL   https://openuserjs.org/meta/nascent/9Convert_Youtube_Download_Button.meta.js
// @downloadURL https://openuserjs.org/install/nascent/9Convert_Youtube_Download_Button.user.js
// @license GPL-3.0-or-later
// ==/UserScript==
//2f2e33 dark gray
//44434a light gray
var AKoiMain = {
    oXHttpReq: null,
    vid: null,
    oldUrl: null,
    DocOnLoad: function (o) {
        try {
            if (null != o && null != o.body && null != o.location && ((AKoiMain.vid = AKoiMain.getVid(o)), AKoiMain.vid)) {
                o.querySelector("#info-contents #info").setAttribute("style", "flex-wrap: wrap;");
                var t = o.querySelector("#menu-container"),
                    e = o.querySelector("#nineconvertconverter"),
                    n = AKoiMain.GetCommandButton();
                null == e && (null != t ? t.parentNode.insertBefore(n, t) : (t = o.querySelector("#eow-title")).parentNode.insertBefore(n, t)), (AKoiMain.oldUrl = o.location.href), AKoiMain.checkChangeVid();
            }
            return !0;
        } catch (o) {
            console.log("Error in function nineconvert.DocOnLoad. ", o);
        }
    },
    checkChangeVid: function () {
        setTimeout(function () {
            AKoiMain.oldUrl == window.location.href ? AKoiMain.checkChangeVid() : AKoiMain.WaitLoadDom(window.document);
        }, 1e3);
    },
    WaitLoadDom: function (o) {
        (AKoiMain.vid = AKoiMain.getVid(o)),
            AKoiMain.vid
                ? null != o.querySelector("#info #menu-container")
                    ? AKoiMain.DocOnLoad(o)
                    : setTimeout(function () {
                          AKoiMain.WaitLoadDom(o);
                      }, 1e3)
                : AKoiMain.checkChangeVid();
    },
    goToY2mate: function (o) {
        try {
            var t = "https://9Convert.com/?query=https://www.youtube.com/watch?v=" + AKoiMain.vid + "";
            window.open(t, "_self");
        } catch (o) {
            console.log("Error In Function nineconvert.OnButtonClick. ", o);
        }
    },
    GetCommandButton: function () {
        try {
            var o = document.createElement("button");
            return (
                (o.id = "nineconvertconverter"),
                (o.className = "yt-uix-tooltip"),
                o.setAttribute("type", "button"),
                o.setAttribute("title", "Download with 9Convert.com"),
                (o.innerHTML = "Download"),
                o.addEventListener(
                    "click",
                    function (o) {
                        AKoiMain.goToY2mate(o);
                    },
                    !0
                ),
                o.setAttribute(
                    "style",
                    "min-height:25px; position:relative; top:1px; cursor: pointer; font: 13px Arial; background: #44434a; color: #fff; text-transform: uppercase; display: block; padding: 10px 16px; margin: 20px 5px 10px 5px; border: 1px solid #44434a; border-radius: 2px; font-weight:bold"
                ),
                o.setAttribute("onmouseover", "this.style.backgroundColor='#2f2e33'"),
                o.setAttribute("onmouseout", "this.style.backgroundColor='#44434a'"),
                o
            );
        } catch (o) {
            console.log("Error in function nineconvert.GetCommandButton. ", o);
        }
    },
    getVid: function (o) {
        var t = o.location.toString().match(/^.*((m\.)?youtu\.be\/|vi?\/|u\/\w\/|embed\/|\?vi?=|\&vi?=)([^#\&\?]*).*/);
        return !(!t || !t[3]) && t[3];
    },
};
AKoiMain.WaitLoadDom(window.document);