Brazen Framework - Utilities

Utilities and helpers for Brazen user scripts framework

このスクリプトは単体で利用できません。右のようなメタデータを含むスクリプトから、ライブラリとして読み込まれます: // @require https://update.greasyfork.org/scripts/375557/1847304/Brazen%20Framework%20-%20Utilities.js

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
作者
brazenvoid
バージョン
4.1.0
作成日
2018/12/15
更新日
2026/06/09
大きさ
13.1KB
ライセンス
GPL-3.0-only

Brazen Framework — Utilities (developer guide)

Foundation module: shared helpers with no site logic. Every other Brazen Framework module depends on this script.

Greasy Fork: Utilities · Loads first among framework modules (after jQuery).


Module constants

Constant Value Use
REGEX_LINE_BREAK /\r?\n/g Split textarea rules (Configuration Manager rulesets)
REGEX_PRESERVE_NUMBERS /\D/g Strip non-digits from strings

ChildObserver

Fluent MutationObserver wrapper for childList add/remove on a single node.

Method Returns Description
ChildObserver.create() ChildObserver Factory
observe(node) this Attach to a DOM Node
onNodesAdded(handler) this (nodes, previousSibling, nextSibling, target) => void
onNodesRemoved(handler) this Same callback signature
pauseObservation() disconnect()
resumeObservation() Re-attach with same options

The framework uses ChildObserver on each itemListSelectors entry so infinite scroll and AJAX lists receive compliance without manual hooks. Use directly only for non-compliance DOM watching.

ChildObserver.create()
  .onNodesAdded((nodes) => { /* ... */ })
  .observe(document.querySelector('#results'))

LocalStore

localStorage wrapper with defaults, change callbacks, and optional nested-object serialization.

Constructor: new LocalStore(key, defaultsObject)

Method Returns Description
get() Object Parse stored JSON; if empty, calls restoreDefaults()
save(data) this JSON.stringify + setItem; fires onChange
delete() this removeItem
restoreDefaults() Object Writes defaults and sets wereDefaultsSet() flag
onChange(handler) this (storeObject) => void after every save
wereDefaultsSet() boolean true when last get() fell back to defaults

Nested objects: If stored JSON has top-level arrays, objects, and properties keys, get() uses Utilities.objectFromJSON for round-trip of nested arrays/objects. Plain JSON objects are returned as parsed.

Configuration Manager wraps two LocalStore instances: {scriptPrefix}settings and {scriptPrefix}settings-id.


SelectorGenerator

Builds prefixed kebab-case selectors for generated UI fragments.

Constructor: new SelectorGenerator(selectorPrefix) — typically scriptPrefix from the app.

Method Returns Example
getSelector(selector) string prefix + selector
getSettingsInputSelector(settingName) string {prefix}{kebab-name}-setting
getSettingsRangeInputSelector(name, getMin) string {prefix}{kebab-name}-min-setting or -max-setting
getStatLabelSelector(statisticType) string Used as element id for stat labels

StatisticsRecorder and View Layer stat widgets use getStatLabelSelector.


StatisticsRecorder

Tracks per-filter removal counts and updates DOM labels.

Constructor: new StatisticsRecorder(selectorPrefix)

Method Description
record(statisticType, validationResult, value = 1) Increments statisticType and Total only when validationResult is falsy (item failed)
getTotal() Sum of all non-compliant hits
reset() Zero all counters
updateUI() Writes counts to elements whose id matches getStatLabelSelector(type)

Pair statisticType with config keys used in createStatisticsFormGroup(key) so bottom-panel labels reflect hide counts.


ComplianceRuleRecorder

Optional per-rule diagnostics when trackComplianceRules: true on the framework.

Method Description
record(configKey, ruleLabel, count = 1) Accumulate hides per filter + rule label
reset() Clear all recorded rules
getReport(resolveFilterLabel?) Sorted report: [{ filterKey, filterLabel, rules: [{ label, count }] }]

resolveFilterLabel maps internal keys to human-readable filter titles (framework passes Configuration Manager field titles).


Utilities (static)

Method Signature Notes
sleep (ms) => Promise Throttles deep attribute loads, paginator fetches, download queue
callEventHandler (handler, params?, defaultValue?) Invokes handler or returns default
callEventHandlerOrFail (name, handler, params?) Throws if handler missing
processEventHandlerQueue (handlers[], params?, defaultValue?) Runs all handlers in order
generateId `(prefix?) => number\ string`
toKebabCase (text) => string Lowercase, spaces → hyphens (tab ids, field keys)
trimAndKeepNonEmptyStrings (strings[]) => string[] Trim + drop empty
buildWholeWordMatchingRegex `(words[]) => RegExp\ null`
objectToJSON (object) => string Nested structure with arrays / objects / properties
objectFromJSON (json) => Object Inverse of objectToJSON
await Utilities.sleep(500)
const pattern = Utilities.buildWholeWordMatchingRegex(['foo', 'bar'])

Validator (static)

Method Signature Behaviour
isInRange (value, lower, upper) => boolean If both bounds > 0: inclusive range. If only lower > 0: value >= lower. If only upper > 0: value <= upper.
doesChildExist (item: JQuery, selector) => boolean item.find(selector).length > 0
isChildMissing (item, selector) => boolean Inverse of above
sanitize (text, rules) => string rules map: regex pattern → replacement string; then trim()
sanitizeTextNode (textNode: JQuery, rules) => Validator Mutates node text
sanitizeNodeOfSelector (selector, rules) => Validator Sanitizes node + document.title
regexMatches (text, rules) => boolean true if no rules or regex matches
validateTextDoesNotContain (text, rules) => boolean true if no rules or regex does not match
iFramesRemover () Injects iframe { display: none !important; } via GM_addStyle

Framework range filters and whitelist/blacklist paths use Validator internally. Custom comply callbacks often call isInRange and regexMatches.


Grants and load order

This module declares no Tampermonkey grants. Grant GM_addStyle, GM_download, GM_getValue, GM_setValue, etc. on the application script as needed.

@run-at document-end

Next in stack: View Layer