VoidPaste

Auto transform pasted image links.

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         VoidPaste
// @namespace    http://tampermonkey.net/
// @version      0.2.0
// @description  Auto transform pasted image links.
// @author       voidnyan
// @match        https://anilist.co/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const imageFormats = [
        "jpg",
        "png",
        "gif",
        "webp",
        "apng",
        "avif",
        "jpeg",
        "svg",
    ];
    const imageWidth = "420";

    let isShiftPressed = false;

    window.addEventListener("keydown", (event) => {
        if (event.key !== "Shift") {
            return;
        }

        isShiftPressed = true;
    });

    window.addEventListener("keyup", (event) => {
        if (event.key !== "Shift") {
            return;
        }

        isShiftPressed = false;
    });

    window.addEventListener("paste", (event) => {
        const clipboard = event.clipboardData.getData("text/plain").trim();

        if (!isShiftPressed){
            return;
        }

        event.preventDefault();
        const rows = clipboard.split("\n");
        let urlList = [];


        for (const row of rows){
            if (!imageFormats.some(format => row.toLowerCase().endsWith(format))) {
                continue;
            }

            urlList.push(`[ img${imageWidth}(${row}) ](${row})`);
        }

        const transformedClipboard = urlList.join("\n\n");

        window.document.execCommand('insertText', false, transformedClipboard);
    });
})();