VoidPaste

Auto transform pasted image links.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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