🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Greasy Fork is available in English.

📂 缓存分发状态(共享加速已生效)
🕒 页面同步时间:2025/12/26 04:06:57
🔄 下次更新时间:2025/12/26 05:06:57
手动刷新缓存

Reddit Full Markdown Editor

Adds a full markdown editor with preview and draft saving to Reddit post and reply boxes

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         Reddit Full Markdown Editor
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Adds a full markdown editor with preview and draft saving to Reddit post and reply boxes
// @author       Mr.K
// @match        https://old.reddit.com/*
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    // Load SimpleMDE and CSS
    var simplemdeScript = document.createElement('script');
    simplemdeScript.src = 'https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js';
    document.head.appendChild(simplemdeScript);

    var simplemdeCss = document.createElement('link');
    simplemdeCss.rel = 'stylesheet';
    simplemdeCss.href = 'https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css';
    document.head.appendChild(simplemdeCss);

    // Add Custom Styles for the Popup
    GM_addStyle(`
        .markdown-editor-popup {
            position: fixed;
            top: 10%;
            left: 50%;
            transform: translateX(-50%);
            width: 80%;
            max-width: 800px;
            background: #fff;
            border: 1px solid #ccc;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            z-index: 1000;
            display: none;
        }
        .markdown-editor-popup-header {
            background: #f6f6f6;
            padding: 10px;
            border-bottom: 1px solid #ccc;
            font-size: 16px;
            font-weight: bold;
            display: flex;
            justify-content: space-between;
        }
        .markdown-editor-popup-body {
            padding: 10px;
        }
        .markdown-editor-popup-footer {
            background: #f6f6f6;
            padding: 10px;
            border-top: 1px solid #ccc;
            display: flex;
            justify-content: flex-end;
        }
        .markdown-editor-drafts {
            margin-top: 10px;
            max-height: 200px;
            overflow-y: auto;
            border-top: 1px solid #ccc;
            padding-top: 10px;
        }
        .markdown-editor-draft-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 5px;
            cursor: pointer;
        }
        .markdown-editor-draft-item:hover {
            background: #e9e9e9;
        }
        .markdown-editor-draft-delete {
            background: red;
            color: white;
            border: none;
            cursor: pointer;
            padding: 5px;
            margin-left: 10px;
        }
    `);

    function createPopup() {
        var popup = document.createElement('div');
        popup.className = 'markdown-editor-popup';
        popup.innerHTML = `
            <div class="markdown-editor-popup-header">
                Markdown Editor
                <button class="markdown-editor-popup-close">X</button>
            </div>
            <div class="markdown-editor-popup-body">
                <textarea id="markdown-editor-textarea"></textarea>
                <div class="markdown-editor-drafts"></div>
            </div>
            <div class="markdown-editor-popup-footer">
                <button class="markdown-editor-save-draft">Save Draft</button>
                <button class="markdown-editor-submit">Submit</button>
            </div>
        `;
        document.body.appendChild(popup);

        var simplemde = new SimpleMDE({ element: document.getElementById('markdown-editor-textarea') });
        return { popup, simplemde };
    }

    function openPopup(simplemde, target) {
        var popup = document.querySelector('.markdown-editor-popup');
        popup.style.display = 'block';
        simplemde.value(target.value);

        // Load drafts
        var draftsContainer = document.querySelector('.markdown-editor-drafts');
        draftsContainer.innerHTML = '';
        var drafts = JSON.parse(localStorage.getItem('markdownEditorDrafts') || '[]');
        drafts.forEach((draft, index) => {
            var draftItem = document.createElement('div');
            draftItem.className = 'markdown-editor-draft-item';
            draftItem.innerHTML = `
                <span>${draft.substring(0, 50)}...</span>
                <button class="markdown-editor-draft-delete" data-index="${index}">Delete</button>
            `;
            draftItem.querySelector('span').onclick = () => simplemde.value(draft);
            draftItem.querySelector('.markdown-editor-draft-delete').onclick = () => {
                deleteDraft(index, simplemde, target);
            };
            draftsContainer.appendChild(draftItem);
        });

        // Handle saving drafts
        document.querySelector('.markdown-editor-save-draft').onclick = () => {
            drafts.push(simplemde.value());
            localStorage.setItem('markdownEditorDrafts', JSON.stringify(drafts));
            alert('Draft saved!');
            openPopup(simplemde, target); // Refresh the drafts list
        };

        // Handle submitting content
        document.querySelector('.markdown-editor-submit').onclick = () => {
            target.value = simplemde.value();
            popup.style.display = 'none';
        };

        // Handle closing the popup
        document.querySelector('.markdown-editor-popup-close').onclick = () => {
            popup.style.display = 'none';
        };
    }

    function deleteDraft(index, simplemde, target) {
        var drafts = JSON.parse(localStorage.getItem('markdownEditorDrafts') || '[]');
        drafts.splice(index, 1);
        localStorage.setItem('markdownEditorDrafts', JSON.stringify(drafts));
        alert('Draft deleted!');
        openPopup(simplemde, target); // Refresh the drafts list
    }

    function init() {
        var { popup, simplemde } = createPopup();

        document.querySelectorAll('.usertext-edit textarea').forEach(textarea => {
            var openEditorButton = document.createElement('button');
            openEditorButton.textContent = 'Open Markdown Editor';
            openEditorButton.style.display = 'block';
            openEditorButton.style.marginBottom = '10px';
            openEditorButton.onclick = () => openPopup(simplemde, textarea);
            textarea.parentNode.insertBefore(openEditorButton, textarea);
        });
    }

    simplemdeScript.onload = init;
})();