MyDealz Kommentar-Editor Speichern/Laden

Speichert und lädt Kommentartexte im MyDealz-Editor mit Strg+S und Strg+L

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         MyDealz Kommentar-Editor Speichern/Laden
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Speichert und lädt Kommentartexte im MyDealz-Editor mit Strg+S und Strg+L
// @author       Claude 3.5 Opus
// @match        https://www.mydealz.de/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Funktion zum Speichern des Kommentartextes
    function saveComment(event) {
        if (event.ctrlKey && event.key === 's') {
            event.preventDefault();
            const articleId = getArticleId();
            const commentText = document.querySelector('.redactor-editor').innerHTML;
            localStorage.setItem(`comment_${articleId}`, commentText);
        }
    }

    // Funktion zum Laden des Kommentartextes
    function loadComment(event) {
        if (event.ctrlKey && event.key === 'l') {
            event.preventDefault();
            const articleId = getArticleId();
            const commentText = localStorage.getItem(`comment_${articleId}`);
            if (commentText) {
                document.querySelector('.redactor-editor').innerHTML = commentText;
            }
        }
    }

    // Funktion zum Extrahieren der Artikel-ID aus der URL
    function getArticleId() {
        const url = window.location.href;
        const match = url.match(/-(\d+)/);
        return match ? match[1] : null;
    }

    // Event-Listener für Tastatureingaben hinzufügen
    document.addEventListener('keydown', saveComment);
    document.addEventListener('keydown', loadComment);
})();