Kyraryc / Streamable Downloader

// ==UserScript==
// @name     Streamable Downloader
// @description Downloads all streamable videos from someone's acount
// @author Kyraryc
// @namespace     http://www.openjs.com/
// @license MIT
// @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 = "Download videos";
        buttonConfig.style.width = '200px';
        buttonConfig.style.background = 'DodgerBlue';
        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");

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

            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);

                if (curviews <= 100)
                {
                    var arg = { url: cururl,
                               name: 'streamables/' + curtitle + curextension + ".mp4",
                               saveAs: false
                              };

                    GM_download(arg);
                    buttonConfig.innerHTML = "Downloaded " + curextension;
                }
            }
            buttonConfig.disabled = false;
            var pagearr = document.getElementsByClassName("page-link");
            pagearr[pagearr.length - 1].click();
        });

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