popoxee / Video Popper V2

// ==UserScript==
// @name         Video Popper V2
// @version      0.0.1
// @description  Find and pop videos! Works with video tags only.
// @author       Mr. B
// @match        *://*/*
// @grant        none
// @license      MIT
// @run-at       document-end
// ==/UserScript==

(() => {
    'use strict'

    const videos = new Set()

    const button = document.createElement("button")
    button.innerText = "Pop Videos"
    button.setAttribute("title", "You might need to play video first to allow videos to be captured")
    button.style.padding = "0px 5px 0px 5px"
    button.style.backgroundColor = "white"
    button.style.color = "black"
    button.style.borderColor = "grey"
    button.style.borderWidth = "1px"

    const div = document.createElement("div")
    //div.setAttribute("display", "none")
    div.style.display = "none"
    div.style.backgroundColor = "white"

    const container = document.createElement("div")
    container.appendChild(button)
    container.appendChild(div)
    container.style.position = "fixed"
    container.style.top = 0
    container.style.left = 0
    container.style.zIndex = 9999

    button.onclick = () => {
        if (div.style.display == "none") {
            div.style.display = "block"
        }
        else {
            div.style.display = "none"
        }
    }

    setInterval(() => {
        videos.clear()

        const videoList = document.querySelectorAll("video[src],video>source[src]")
        videoList.forEach(v => {
            const src = v.getAttribute("src")
            if (!src.startsWith("blob")) {
                videos.add(src)
            }
        })

        div.innerHTML = ""

        videos.forEach(x => {
            const link = document.createElement("a")
            link.setAttribute("href", x)
            link.setAttribute("target", "_blank")
            link.innerText = x

            div.appendChild(link)
            div.appendChild(document.createElement("br"))
        })

        if (videos.size > 0 && container.parentNode == null) {
            document.body.insertBefore(container, document.body.firstChild)
        }
        else if (videos.size == 0 && container.parentNode != null) {
            document.body.removeChild(container)
        }
    }, 1000)

})();