Utilities and helpers for Brazen user scripts framework
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.greatest.deepsurf.us/scripts/375557/1847304/Brazen%20Framework%20-%20Utilities.js
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).
| 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 |
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'))
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.
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.
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.
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).
| 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'])
| 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.
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