A CodeMirror 6 based rule editor with Regex validation, search, and theme switching.
Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greasyfork.org/scripts/566628/1896077/RuleEditor.js
This editor is built on CodeMirror 6, integrating custom syntax highlighting, regular expression validation, real-time search navigation, and multi-theme switching.
Initialize the editor by instantiating the RuleEditor class.
const container = document.getElementById('editor-container');
const editor = new RuleEditor(container, {
content: "# Initial rules\n/example/g",
darkMode: false
});darkMode (boolean)true for dark mode, false for light mode.editor.darkMode = true;setContent(content, keepHistory)content (string): The new text content.keepHistory (boolean, default false): When false, resets undo history and syncs baseline snapshot.getContent()updateSnapshot()restoreToSnapshot()setSearch(term)findNext()findPrev()Assign callback functions directly to instance properties:
onDirtyChangeisDirty (boolean) — Indicates whether the document has been modified.editor.onDirtyChange = (isDirty) => { console.log(isDirty); };onSearchUpdate{ total, current, isExact }total: Total number of matched lines.current: Line index closest to the current cursor position (1-based).isExact: Whether the cursor is exactly on a matched line.editor.onSearchUpdate = (res) => { console.log(res); };getRules(){ regexes, keywords, errors }regexes: Array of valid RegExp objects [{ pattern, flags }].keywords: Array of recognized keyword strings [string].errors: Array of invalid RegExp objects and position info [{ text, from, to, line }].destroy()The editor supports the following three basic syntax elements:
/pattern/flags format with real-time syntax validation and error reporting.#.This project is built on top of the CodeMirror 6 core library, with interaction design and UI inspiration drawn from uBlacklist and uBlock Origin.