Polytoria Image Markdown Userscript

Adds image markdown support to Polytoria forums

04.08.2023 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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);
            }
        }
    }
}