Greasy Fork is available in English.

theYNC

Unlock underground videos

لقد تم حذف هذا البرنامج النصي.

// ==UserScript==
// @name         theYNC
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Unlock underground videos
// @author       reagent
// @include      /https://theync\.com/.+/[uU]nderground/.+/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const getURL = URL => URL.replace("thumbs.theync.com/thumbs", "media.theync.com/videos").replace(/\.[^.\/]+\/[^\/]*$/g, ".mp4")
    const {modal, backdrop, setVideo, setHeader, show, hide} = createVideoModal();

    document.body.appendChild(modal);
    document.body.appendChild(backdrop);

    const cols = document.querySelectorAll(".content-block .item-normal.item-block.col");

    for(const col of cols){
        const img = col.querySelector("img");
        const title = img.getAttribute("alt");
        const newURL = getURL(img.getAttribute("src"));
        const links = col.querySelectorAll("a");

        for(const link of links){
            link.addEventListener("click", e => {
                e.preventDefault();
                setHeader(title);
                setVideo(newURL);
                show();
            });
        }
    }

    function createVideoModal(){
        const header = (() => {
            let el = document.createElement("h5");
            el.setAttribute("class", "modal-title");
            el.style.color = "black";
            return el;
        })();
        const setHeader = newHeader => header.textContent = newHeader;
        const video = (() => {
            let el = document.createElement("video");
            el.setAttribute("controls", "true");
            el.setAttribute("autoplay", "true");
            el.setAttribute("class", "embed-responsive-item");
            return el;
        })();
        const setVideo = newURL => video.src = newURL;
        const closeButtons = [];
        const modal = (() => {
            let el = document.createElement("div");
            el.setAttribute("class", "modal");
            el.setAttribute("role", "dialog");
            el.style.display = "none";
            el.appendChild((() => {
                let el = document.createElement("div");
                el.setAttribute("class", "modal-dialog");
                el.setAttribute("role", "document");
                el.addEventListener("click", event => event.stopPropagation());
                el.appendChild((() => {
                    let el = document.createElement("div");
                    el.setAttribute("class", "modal-content");
                    el.appendChild((() => {
                        let el = document.createElement("div");
                        el.setAttribute("class", "modal-header");
                        el.appendChild((() => {
                            let el = document.createElement("button");
                            el.setAttribute("type", "button");
                            el.setAttribute("class", "close");
                            el.setAttribute("data-dismiss", "modal");
                            el.setAttribute("aria-label", "Close");
                            el.appendChild((() => {
                                let el = document.createElement("span");
                                el.setAttribute("aria-hidden", "true");
                                el.appendChild(document.createTextNode("×"));
                                return el;
                            })());
                            closeButtons.push(el);
                            return el;
                        })());

                        el.appendChild(header);
                        return el;
                    })());
                    el.appendChild((() => {
                        let el = document.createElement("div");
                        el.setAttribute("class", "modal-body");
                        el.appendChild((() => {
                            let el = document.createElement("div");
                            el.setAttribute("class", "embed-responsive embed-responsive-16by9");
                            el.appendChild(video);
                            return el;
                        })());
                        return el;
                    })());
                    el.appendChild((() => {
                        let el = document.createElement("div");
                        el.setAttribute("class", "modal-footer");
                        el.appendChild((() => {
                            let el = document.createElement("button");
                            el.setAttribute("type", "button");
                            el.setAttribute("class", "btn btn-secondary");
                            el.setAttribute("data-dismiss", "modal");
                            el.appendChild(document.createTextNode("Close"));
                            closeButtons.push(el);
                            return el;
                        })());
                        return el;
                    })());
                    return el;
                })());
                return el;
            })());
            closeButtons.push(el);
            return el;
        })();
        const backdrop = (() => {
            const el = document.createElement("div");
            el.className = "modal-backdrop fade in"
            el.style.display = "none"
            return el;
        })()
        const show = () => {
            modal.style.display = backdrop.style.display = "block";
            document.body.classList.add("modal-open")
        }
        const hide = () => {
            modal.style.display = backdrop.style.display = "none";
            document.body.classList.remove("modal-open")
            video.pause();
        }
        for(const closeButton of closeButtons){
            closeButton.addEventListener("click", hide);
        }
        return {modal, backdrop, setVideo, setHeader, show, hide};
    }
})();