spellRicher

简单富文本编辑

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/534392/1580077/spellRicher.js

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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 सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

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

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

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

//altered from https://github.com/ninja33/ODH/blob/master/src/fg/js/spell.js
;

function spell() {
    let exec = (command, value = null) => document.execCommand(command, false, value)
    let ensureHTTP = url => /^https?:\//.test(url) ? url : `https://${url}`
    let $ = (tag, props, children = [], elm = document.createElement(tag)) =>
        children.map(child => child && elm.appendChild(child)) && Object.assign(elm, props)

    let colorPicker = _ => $('input', {type: 'color'})
    let select = options => $('select', {}, options.map(o => $('option', {textContent: o})))

    let buttons = {};
    let queryState = _ => {
        for (let cmd in buttons)
            buttons[cmd].classList.toggle('selected', document.queryCommandState(cmd))
    }

    let actions = [
        [
            ['bold'],
            ['italic'],
            ['underline']
        ],
        [
            ['paragraph', '<p>'],
            ['quote', '<blockquote>'],
            ['code', '<pre>']
        ].map(([title, format]) => [title, _ => exec('formatBlock', format)]),
        [
            ['insertOrderedList'],
            ['insertUnorderedList'],
            ['insertHorizontalRule'],
        ],
        [
            ['removeFormat'],
            ['unlink']
        ],
        [
            ['createLink', 'link', ensureHTTP],
            ['insertImage', 'image', img => img]
        ].map(([cmd, type, t]) => [type, url => (url = prompt(`Enter the ${type} URL`)) && exec(cmd, t(url))]),
        [
            ['undo'],
            ['redo']
        ]
    ]

    return $('div', {className: 'spell'}, [
        $('div', {className: 'spell-bar'}, actions.map(
            bar => $('div', {className: 'spell-zone'}, bar.map(
                ([cmd, onclick = _ => exec(cmd), control]) => buttons[cmd] = $('button', {
                    className: 'spell-icon',
                    title: cmd.replace(/([^a-z])/g, ' $1').toLowerCase(),
                    onclick
                }, [$('i', {className: 'icon-' + cmd.toLowerCase()}), control])
            ))
        )),
        $('div', {
            className: 'spell-content',
            contentEditable: true,
            onkeydown: event => event.which !== 9,
            onkeyup: queryState,
            onmouseup: queryState
        })
    ])
}