Semprot Helpers

Semprot Helper

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Advertisement:

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

Advertisement:

// ==UserScript==
// @name         Semprot Helpers
// @description  Semprot Helper
// @author       Pommpol
// @version      2.2.2
// @match        https://www.semprot.com/threads/*
// @match        https://www.semprot.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=semprot.com
// @grant        GM_xmlhttpRequest
// @license MIT
// @namespace https://sleazyfork.org/en/scripts/584781
// ==/UserScript==
(function () {
    "use strict";
    const URLPattern = {
        isDood(url) {
            const doodUrl = ["dsvplay.com", "myvidplay.com", "playmogo.com"];
            return doodUrl.some((domain) => url.hostname.endsWith(domain));
        },
        isStreamtape(url) {
            const streamtapeURL = ["streamtape.com"];
            return streamtapeURL.some((domain) => url.hostname.endsWith(domain));
        },
        isVidara(url) {
            const vidaraURL = ["vidara.to", "vidara.so", "vidaarax.net"];
            return vidaraURL.some((domain) => url.hostname.endsWith(domain));
        },
    };
    // --- STYLES ---
    const injectStyles = () => {
        const style = document.createElement("style");
        style.innerHTML = `
            .swapping { filter: blur(5px) grayscale(80%); transition: filter 0.5s ease; cursor: wait; }
            .iframe-wrapper { position: relative; margin-top: 10px; }
            .sh-close-btn { position: absolute; top: 0; right: 0; background: red; color: white; border-radius: 10%; border: 2px solid white; cursor: pointer; padding: 0.5rem; margin: 0; }
            .spin { animation: spin 5s linear infinite; }
            @keyframes spin {
                0% { transform: rotate(0deg); }
                100% { transform: rotate(360deg); }
            }
        `;
        document.head.appendChild(style);
    };
    // --- SERVICES ---
    const MediaService = {
        async fetchImageBam(url) {
            console.log(`Trying to get ${url}...`);
            var date = new Date();
            date.setTime(date.getTime() + (6 * 60 * 60 * 1000));
            const expires = date.toUTCString();
            return new Promise((resolve) => {
                GM_xmlhttpRequest({
                    method: "GET",
                    url: url,
                    headers: { Cookie: `sfw_inter=1; nsfw_inter=1;expires=${expires}; path=/` },
                    onload: (res) => {
                        const doc = new DOMParser().parseFromString(res.responseText, "text/html");
                        const img = doc.querySelector("img.main-image");
                        resolve(img ? img.src : null);
                    },
                });
            });
        },
    };
    // --- CORE ---
    const App = {
        observer: null,
        init() {
            injectStyles();
            this.setupObserver();
            this.bindGlobalEvents();
        },
        setupObserver() {
            this.observer = new IntersectionObserver(
                (entries) => {
                    entries.forEach((entry) => {
                        if (entry.isIntersecting && entry.target.dataset.pendingSrc) {
                            const img = entry.target;
                            img.src = img.dataset.pendingSrc;
                            img.onload = () => {
                                img.classList.remove("swapping");
                                img.classList.contains("img-large")
                                    ? img.classList.remove("img-large")
                                    : img.classList.add("img-large");
                                delete img.dataset.pendingSrc;
                            };
                            this.observer.unobserve(img);
                        }
                    });
                },
                { rootMargin: "100px" },
            );
        },
        bindGlobalEvents() {
            document.addEventListener(
                "click",
                async (e) => {
                    const target = e.target;
                    const link = target.closest("a");
                    const url = new URL(link.href);
                    let embedUrl = null;
                    // Video Embedding
                    if (link) {
                        if (url.hostname.includes("sendvid.com")) {
                            embedUrl = `https://${url.hostname}/embed/${url.pathname}`;
                        } else if (
                            URLPattern.isStreamtape(url) ||
                            URLPattern.isDood(url) ||
                            URLPattern.isVidara(url)
                        ) {
                            embedUrl = `https://${url.hostname}/e/${url.pathname.split("/")[2]}`;
                        }
                        if (embedUrl) {
                            e.preventDefault();
                            this.spawnIframe(link, embedUrl);
                        }
                    }
                    // ImageBam
                    if (target.tagName === "IMG") {
                        if (target.classList.contains("swapping")) return;
                        const parentLink = target.closest("a");
                        if (parentLink?.href.includes("imagebam")) {
                            e.preventDefault();
                            if (target.classList.contains("img-large")) {
                                const oriUrl = target.dataset.url;
                                if (oriUrl) this.swapImage(target, oriUrl);
                            } else {
                                const fullSrc = await MediaService.fetchImageBam(parentLink.href);
                                if (fullSrc) this.swapImage(target, fullSrc);
                            }
                        }
                    } else {
                        if (url.hostname.includes("imagebam.com")) {
                            e.preventDefault();
                            if (link.querySelector("img") !== null) return;
                            if (link.classList.contains("append-img")) return;
                            const img = document.createElement("img");
                            img.className = "spin";
                            link.className = "append-img";
                            img.onclick = function () {
                                link.classList.remove("append-img");
                                this.remove();
                            };
                            img.src = "https://cdn-icons-png.flaticon.com/128/3305/3305803.png";
                            link.appendChild(img);
                            const full = await MediaService.fetchImageBam(url);
                            if (full) {
                                img.classList.remove("spin");
                                this.swapImage(img, full);
                            }
                        }
                    }
                },
                true,
            );
        },
        swapImage(img, newSrc) {
            img.classList.add("swapping");
            img.dataset.pendingSrc = newSrc;
            this.observer.observe(img);
        },
        spawnIframe(anchor, url) {
            if (anchor._iframeWrapper) {
                anchor._iframeWrapper.remove();
                anchor._iframeWrapper = null;
                return;
            }
            const wrapper = document.createElement("div");
            wrapper.className = "iframe-wrapper";
            wrapper.innerHTML = `
                <button class="sh-close-btn">Close</button>
                <iframe width="560" height="315" src="${url}" frameborder="0" allowfullscreen></iframe>
            `;
            wrapper.querySelector(".sh-close-btn").onclick = () => {
                wrapper.remove();
                anchor._iframeWrapper = null;
            };
            anchor.after(wrapper);
            anchor._iframeWrapper = wrapper;
        },
    };
    App.init();
})();