Brazen Framework - Configuration Manager

Configuration management for the Brazen user scripts framework

Dit script moet niet direct worden geïnstalleerd - het is een bibliotheek voor andere scripts om op te nemen met de meta-richtlijn // @require https://update.greasyfork.org/scripts/418665/1877678/Brazen%20Framework%20-%20Configuration%20Manager.js

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Advertisement:

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

Advertisement:

Maker
brazenvoid
Versie
5.1.2
Gemaakt op
15-12-2020
Bijgewerkt op
16-07-2026
Grootte
93,4 KB
Licentie
GPL-3.0-only

Brazen Framework - Configuration Manager

File BrazenConfigurationManager.js
Type Brazen Framework module
@name Brazen Framework - Configuration Manager
Version 5.1.2
Greasy Fork 418665
License GPL-3.0-only

Requires

Dependency Load order
BrazenUtilities.js 1
BrazenViewLayer.js 2
BrazenIndexedDBStorage.js 3

Uses legacyStorageHasData, readLegacySettingsAggregate from IndexedDB Storage; BrazenStorageRepositories, Utilities, REGEX_LINE_BREAK.

Required by

Runtime

Grants none

Module constants

Constant Value
CONFIG_TYPE_CHECKBOXES_GROUP 'checkboxes'
CONFIG_TYPE_COLOR 'color'
CONFIG_TYPE_FLAG 'flag'
CONFIG_TYPE_NUMBER 'number'
CONFIG_TYPE_RADIOS_GROUP 'radios'
CONFIG_TYPE_RANGE 'range'
CONFIG_TYPE_RULESET 'ruleset'
CONFIG_TYPE_SELECT 'select'
CONFIG_TYPE_TEXT 'text'
CONFIG_TYPE_BOOKMARKS 'bookmarks'
CONFIG_TYPE_LEDGER 'ledger'
CONFIG_BACKUP_VERSION 3

Class: BrazenConfigurationManager

Members follow README.md.

Constructor

new BrazenConfigurationManager(scriptPrefix: string, uiGenerator: BrazenViewLayer, tagSelectorGenerator: SearchEnhancerTagSelectorGeneratorCallback)

Field registration (integral args → returns ConfigurationField; chain set* for optionals)

Method Signature
addFlagField addFlagField(key: string)setTitle, setHelpText, setDefault, dock setters
addTextField addTextField(key: string)setTitle, setHelpText, setDefault, dock setters
addNumberField addNumberField(key: string, minimum: int, maximum: int)setTitle
addColorField addColorField(key: string)setTitle
addRangeField addRangeField(key: string, minimum: int, maximum: int)setTitle
addSelectField addSelectField(key: string, keyValuePairs: array)setTitle
addCheckboxesGroup addCheckboxesGroup(key: string, keyValuePairs: array)setTitle
addRadiosGroup addRadiosGroup(key: string, keyValuePairs: array)setTitle
addRulesetField addRulesetField(key: string)setTitle, setRows, setHelpText, translate/format/optimize/sort setters
addTagRulesetField addTagRulesetField(key: string, useSelectors: boolean)
addActionField addActionField(key: string)setTitle, setAction / setOnClick, dock setters; persist: false
addBookmarksField addBookmarksField(key: string)setTitle, bookmark set* chain, .reload()
addLedgerField addLedgerField(key: string)setTitle, ledger set* chain, .reload()

Dock field setters (on field): setDockButton, applyDockTemplate(name, args?), setDockSlideOut, setDockSlideOutNodes, setOnClick, setAction

Dock templates (applyDockTemplate): named recipes with baked copy — tagBlacklist, exploredTags, autoDownload, autoNextPage, defaultTags, resolutionFilter, hideOlderPosts, invertedFiltersMaster, skipDuplicates, hideDownloaded. Generic flagToggle is an escape hatch. Consumers call by name only; sparse args are for dock-behavior overrides when a case arises.

Dock manager methods: setDockActive(bool), onDockToggle(callback), createDockElement(name), getDockRootFields(), refreshDockButtonStates(), evaluateDockInclude(name)

Accessors

Method Signature
getField `getField(name: string) → ConfigurationField\
getFieldOrFail getFieldOrFail(name: string) → ConfigurationField
getValue getValue(name: string) → * — reads _settingCache when canPersist()
getOptimized getOptimized(name: string) → * — reads cached optimized when canPersist()
hasField hasField(name: string) → boolean
createElement createElement(name: string) → JQuery

Ruleset field API (on ConfigurationField from addRulesetField / addTagRulesetField)

Property / method Role
onMatchRule(storedRule, target) Optional (storedRule, target) → boolean; default strict equality
setRules(lines) onTranslateFromUI → optional sortRules (string key via onFormatForUI for object rules) → valueonOptimizeupdateUserInterface
findRuleIndex(target) First match index or -1
hasRule(target) Membership via onMatchRule
addRule(rule, target?) Upsert then setRules
removeRule(target) Filter matches then setRules
toggleRule(rule, target?) Add or remove
clearRules() setRules([])

setRules does not deduplicate; setFromUserInterface still runs _deduplicateRulesetRules.

Lifecycle

Method Signature
initialize async initialize() → Promise<BrazenConfigurationManager> — opens per-script IndexedDB (brazen-{prefix}), runs setup (legacy import + setScriptSetup handler) when unhealthy, then normal phase
setScriptSetup setScriptSetup(handler: (repos, cm) => Promise<void>) → this
getRepos getRepos() → BrazenStorageRepositories
isStorageReady isStorageReady() → boolean
isIdbBlocked isIdbBlocked() → boolean
update update() → BrazenConfigurationManager
readSetting async readSetting(fieldKey) → Promise<*> — IDB source of truth via _settingCache
writeSetting async writeSetting(fieldKey, value) → Promise<BrazenConfigurationManager> — direct IDB put; updates cache; bumps revision
save async save() → Promise<BrazenConfigurationManager> — mounted panel fields only (field.element required); tag-domain rulesets import textarea lines
revertChanges async revertChanges() → Promise<BrazenConfigurationManager>
updateInterface updateInterface() → BrazenConfigurationManager
notifyConfigurationChange `notifyConfigurationChange(source?: 'settings'\
onConfigurationChange onConfigurationChange(handler) → thissingle slot (Framework only); event { manager, source, local }
onExternalConfigurationChange onExternalConfigurationChange(handler) → thisdeprecated alias for onConfigurationChange; scripts should use Framework onConfigurationChange
reloadBookmarkFields async reloadBookmarkFields() → Promise<BrazenConfigurationManager> — reload bookmark rows + widget render (called by Framework handler)

Backup

Method Signature
backup async backup() → Promise<void> — zip bundle (manifest.json + one JSON file per IDB store)
restore async restore(response: Response) → void — v3 zip/JSON; v2/v1 import to IDB via _importV2BackupToIdb / _importLegacyBackupToIdb

Validation

Method Signature
generateValidationCallback generateValidationCallback(configKey: string) → (value) => boolean

Typedef: ConfigurationField

key, title, setTitle(title), type, element, value, helpText, minimum, maximum, options, optimized?, persist?, widget?, serializeForBackup?, applyFromBackup?, createElement, setFromUserInterface, updateUserInterface, onTranslateFromUI, onFormatForUI, onOptimize, sortRules?

Ledger fields additionally expose: downloadedIds, reload(), has(id), claim(ids), merge(registry). IndexedDB-only when canPersist(); claim returns true and has returns false when persistence is disabled.

Bookmark fields additionally expose: reload(), _bookmarkRows, serializeForBackup(), applyFromBackup() (replace via repository). Widget CRUD uses BookmarkRepository directly.

Tag registry (Configuration Manager)

Method Role
getTagRuntime() Session TagRuntime
isTagRegistryField(fieldKey) Field in TAG_FIELD_SPEC
hasTagSoleAttribute(fieldKey, tagName) Sole attribute read (registry or hasRule fallback)
hasTagSubstitutionSubject(tagName, fieldKey?) Substitution subject check
setTagSubstitution(subject, replacement, fieldKey?) Persist alias → canonical
clearTagSubstitution(subject, fieldKey?) Remove substitution for subject
hasTagComplianceRules(fieldKey) Compliance filter active predicate
refreshTagComplianceSpecs(fieldKeys?), getTagComplianceSpec(fieldKey), evaluateTagCompliance(itemTags, fieldKey) Compliance runtime
createTagContext(options) Context for patchAttributes / toggles
registerTypedTagGroups(groups, source?) Register-on-seen from typed groups
prepareTagComplianceRuntime() Compile + warm + refresh specs
applyTagRegistryDownloadResolver(resolver) Route download policy through registry
clearTagDomain() Wipe tag registry, rules, compiled sets; empty panel projection
clearDownloadLedger() Wipe ledgerEntries and reload download-ledger.downloadedIds
clearScriptDatabase() Delete this script’s IndexedDB database entirely (caller should reload)

Private behaviour

Method Role
_settingCache Map<fieldKey, {value, optimized}> — source of truth for settings/tag-domain reads when canPersist()
_cacheSetting, _getCachedSetting, _overlayFieldFromCache, _refreshSettingCacheFromIdb Cache helpers
_formatFieldKey(name) Utilities.toKebabCase(name)
_createField(type, name, value, helpText) Create or update field entry; seeds cache
_syncFieldsFromIdb() Calls _refreshSettingCacheFromIdb()
_syncFieldFromIdb(fieldKey) Lazy hydrate single field into cache (mounted fields, tag domain)
_importV2BackupToIdb, _importLegacyBackupToIdb, _importFlatBackupFieldsToIdb v2/v1 backup import to IDB repositories
_restoreV3Backup(backupConfig) Direct store write for v3 zip bundle
_deduplicateRulesetRules(rules) Drop duplicate rule lines (case-sensitive; first wins)
_optimizeTagRuleset(rules, useSelectors) Parse &/`\

Cross-tab: document.visibilitychange compares meta.revisionId to _syncedRevisionId; reloads cache and bookmark field rows, then notifyConfigurationChange('all', false) only when the revision differs. Local writes advance _syncedRevisionId immediately via BrazenStorageRepositories onRevisionBump (every MetaRepository.bumpRevision()), so focus after a same-tab write is a no-op and does not wipe unsaved panel edits.

Tag field commit: _commitTagFieldChange bumps revision (cursor already tracked), notifies tags first so UI can paint from writer-updated cache entries, then warms TagRuntime (atomic map swap). Sole-attribute toggleTagRule also notifies early after flipping the cached entry, before IDB put/compile. Framework does not reload settings textareas for local tags events.

Configuration change: CM notifies with { manager, source, local }; Framework debounces and gates refreshMountedFields (local settings/all or foreign config only), then script onConfigurationChange hooks.

Purpose

Typed settings schema, pluggable storage drivers, cross-tab sync, and UI element factory.

Artifacts

File Role
BrazenConfigurationManager.md Developer guide
BrazenConfigurationManager.changelog.md Changelog

Breaking changes

See BrazenConfigurationManager.changelog.md.

Known issues

  • addSelectFieldcreateElement builds a radio group (createFormRadiosGroupSection) then queries find('select'), so the select UI is never created. Use addRadiosGroup or build a custom dropdown via View Layer createFormGroupDropdown until fixed.