A CodeMirror 6 based rule editor with Regex validation, search, and theme switching.
Script này sẽ không được không được cài đặt trực tiếp. Nó là một thư viện cho các script khác để bao gồm các chỉ thị meta
// @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.