Kyraryc / Streamable Deletion Saver

// ==UserScript==
// @name     Streamable Deletion Saver
// @description Opens "Pending Deletion" videos in new tabs
// @author Kyraryc
// @license MIT
// @namespace     http://www.openjs.com/
// @match        https://*.streamable.com/*
// @grant        GM_download
// @grant        GM_info
// @grant       GM.setValue
// @grant       GM.getValue
// @version  1
// ==/UserScript==


(function()
 {
    var url = window.location.href;

    if (url.includes("streamable"))
    {
        var buttonConfig = document.createElement("button");
        buttonConfig.innerHTML = "Opens at risks";
        buttonConfig.style.width = '200px';
        buttonConfig.style.background = 'Chocolate';
        buttonConfig.style.color = 'white';
        buttonConfig.addEventListener("click", function() {

            var titlearr = document.getElementsByClassName("form-control edit-title-input");
            var viewsarr = document.getElementsByClassName("header-item float-right");
            var vidarr = document.getElementsByClassName("video-url");
            var allcards = document.getElementsByClassName("grid video-item");

            if (viewsarr.length != vidarr.length)
            {
                return;
            }

            var atriskvids = "";
            for (let i = 0; i < viewsarr.length; i++)
            {
                var curviews = viewsarr[i].innerText.replace("views", "").trim();
                var cururl = vidarr[i].innerText.toLowerCase().replace("copy link", "").trim();
                var curtitle = titlearr[i].value;
                var curextension = cururl.substring(cururl.lastIndexOf("/") + 1);
                var atrisks = allcards[i].getElementsByClassName("stale-notification");

                if (atrisks.length != 0)
                {
                    atriskvids = atriskvids + "," + cururl;
                    window.open(cururl, "_blank");
                }
            }

            buttonConfig.disabled = false;
            var pagearr = document.getElementsByClassName("page-link");
            pagearr[pagearr.length - 1].click();
        });

        var body = document.getElementsByClassName("navbar")[0];
        body.appendChild(buttonConfig);
    }
})();