A CodeMirror 6 based rule editor with Regex validation, search, and theme switching.
Questo script non dovrebbe essere installato direttamente. È una libreria per altri script da includere con la chiave // @require https://update.greasyfork.org/scripts/566628/1756739/RuleEditor.js
This editor is built on CodeMirror 6, featuring custom syntax highlighting, regex validation, real-time search navigation, and multi-theme support.
Initialize the editor and get the control instance via the window.CodeMirror6 global object.
const container = document.getElementById('editor-container');
const editor = window.CodeMirror6.createEditor(container);setContent(content, keepHistory)keepHistory (boolean) is false, it resets the undo history and updates the sync snapshot.getContent()updateSnapshot()setTheme(isDark)true for Dark mode, false for Light mode.setSearch(term)findNext()findPrev()onSyncStatusChange(callback)isSynced (boolean).onSearchUpdate(callback){ total, current, isExact }total: Total number of matching lines.current: Current match index closest to the cursor (starting from 1).isExact: Whether the cursor is exactly positioned on a matching line.getRules(){ regexps, keywords, errors }regexps: List of valid regular expressions.keywords: List of identified keyword strings.errors: Syntax errors including text and position info.The editor supports three basic syntax elements:
/pattern/flags format with real-time validity linting.# (entire line or end-of-line).This project is built upon the CodeMirror 6 core library, with interactive logic and UI design inspired by uBlacklist and uBlock Origin.