Polytoria Image Markdown Userscript

Adds image markdown support to Polytoria forums

Verze ze dne 04. 08. 2023. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Polytoria Image Markdown Userscript
// @description  Adds image markdown support to Polytoria forums
// @version      1.0.3
// @author       Hawli The Hawli
// @license      LGPLv2.1   
// @match        https://polytoria.com/forum/post/*
// @namespace https://greasyfork.org/users/1142699
// ==/UserScript==

const classes = document.getElementsByClassName("mb-0 w-100");
for (let i = 0; i < classes.length; i++) {

    const paragraphs = classes[i].querySelectorAll('p:not([class]):is(p)');

    for (let i = 0; i < paragraphs.length; i++) {

        let paragraph = paragraphs[i]

        const a = paragraph.querySelector('a');

        if (a != null) {
            var url = a.href;
            url = url.slice(0, -1);

            const stupid = paragraph.querySelectorAll('i');
            stupid.forEach(i => {
                i.remove();
            });

            if (url.startsWith("https://i.imgur.com/")) {
                const img = document.createElement('img');
                img.src = url;

                const before = a.previousSibling;

                a.parentElement.removeChild(before);

                a.parentElement.replaceChild(img, a);
                img.classList.add('img-fluid')
                img.classList.add('w-50')
                img.style.borderRadius = "15px";
                img.style.paddingTop = "5px";
                img.style.paddingBottom = "5px";
            }

            if (url.startsWith("https://www.youtube.com/embed/")) {
                var youtubeUrl = a.href;
                youtubeUrl = youtubeUrl.replace(")", '');

                const iframe = document.createElement('iframe');
                const div = document.createElement('div');
                iframe.src = youtubeUrl;

                const before = a.previousSibling;

                a.parentElement.removeChild(before);

                a.parentElement.replaceChild(div, a);
                div.style.cssText = "width: 640px; height: 360px;"
                iframe.style.cssText = 'height: 100%; width: 100%'
                iframe.style.borderRadius = "15px";
                div.appendChild(iframe);
            }

            if (url.startsWith("https://www.youtube.com/watch?v=")) {
                var youtubeUrl = a.href;
                youtubeUrl = youtubeUrl.replace("/watch?v=", "/embed/");
                youtubeUrl = youtubeUrl.replace(")", '');
                

                const iframe = document.createElement('iframe');
                const div = document.createElement('div');
                iframe.src = youtubeUrl;

                const before = a.previousSibling;

                a.parentElement.removeChild(before);

                a.parentElement.replaceChild(div, a);
                div.style.cssText = "width: 640px; height: 360px;"
                iframe.style.cssText = 'height: 100%; width: 100%'
                iframe.style.borderRadius = "15px";
                div.appendChild(iframe);
            }
        }
    }
}