VoidPaste

Auto transform pasted image links.

Skript installieren?
Vom Ersteller vorgeschlagenes Skript

Ihnen könnte auch VoidVerified gefallen.

Skript installieren

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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 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.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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