Markdown Viewer

This is to preview the markdown text as HTML page

Από την 09/10/2025. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Markdown Viewer
// @namespace    https://docs.scriptcat.org/
// @version      0.1.0
// @description  This is to preview the markdown text as HTML page
// @author       You
// @match        https://*/*/*.md
// @match        http://*/*/*.md
// @inject-into  content
// @require      https://cdn.jsdelivr.net/npm/[email protected]/lib/marked.umd.min.js
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    const pre = document.querySelector("body>pre:only-child");
    if (pre) {
        const text = pre.textContent;
        if (text) {
            const div = document.createElement("div");
            div.id = "markdown-render";
            div.innerHTML = marked.parse(text);
            pre.replaceWith(div);
            GM_addStyle(`
                body {
                    all: unset;
                }
                #markdown-render {
                    margin: 16px;
                    padding: 16px;
                    border: 1px solid currentColor;
                    position: relative;
                    box-sizing: border-box;
                    max-height: calc( 100vh - 32px );
                    max-width: calc( 100vw - 32px );
                    overflow: auto;
                }
                #markdown-render img {
                    max-width: 100%;
                }
            `);
        }
    }
    // Your code here...
})();