VoidPaste

Auto transform pasted image links.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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