Item attributes resolution for the 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.greasyfork.org/scripts/429587/1847311/Brazen%20Framework%20-%20Item%20Attributes%20Resolver.js
Resolve per-tile metadata for compliance filters when search results do not expose everything on the thumbnail row.
Greasy Fork: Item Attributes Resolver · Requires: Utilities · Used by: Framework core
Class name: BrazenItemAttributesResolver (filename uses singular Attribute).
new BrazenItemAttributesResolver({
itemLinkSelector: 'a.thumb', // href for deep fetch
itemDeepAnalysisSelector: '#metadata', // fragment loaded from detail page
requestDelay: 200, // ms multiplier between deep loads
onDeepAttributesResolution: (item) => { /* re-run compliance */ },
})
Framework wires onDeepAttributesResolution to _complyItem(item) + _onAfterComplianceRun.
Resolved values live on the DOM node: item[0].scriptAttributes — a plain object keyed by normalized attribute names.
Attribute names are formatted: attribute.toLowerCase().replaceAll(' ', '_').
| Registration | When it runs | Framework usage |
|---|---|---|
addAttribute(name, extractor) |
During resolveAttributes(item) on first compliance pass |
Shallow read from list tile |
addAsyncAttribute(name, extractor) |
Not auto-invoked by framework | Register for custom/manual use |
addDeepAttribute(name, extractor) |
Lazy — when get() misses and deep attrs exist |
Detail-page scrape |
this._itemAttributesResolver.addAttribute('tags', (item) => {
return item.find('.tag').map((i, el) => $(el).text()).get()
})
resolveAttributes(item) creates scriptAttributes, runs all shallow extractors, does not call async or deep extractors.
When get(item, 'tags') returns undefined and _hasDeepAttributes:
href from item.find(itemLinkSelector).first().Utilities.sleep(_requestIteration * requestDelay) — throttles parallel fetches.#brazen-item-attributes-resolver-sandbox loads url + ' ' + itemDeepAnalysisSelector.onDeepAttributesResolution(item) fires._requestIteration incremented.this._itemAttributesResolver.set(item, 'synthetic_tag', 'value')
Use in _onFirstHitBeforeCompliance when parsing tile DOM before filters run.
| Method | Role |
|---|---|
addAttribute(name, callback) |
Shallow extractor (item: JQuery) => * |
addAsyncAttribute(name, callback) |
Stored only; not called by resolveAttributes |
addDeepAttribute(name, callback) |
Deep extractor (sandbox: JQuery) => * |
resolveAttributes(item, afterCallback?) |
First-pass shallow resolution |
get(item, attribute) |
Read value; may trigger deep load |
set(item, attribute, value) |
Write into scriptAttributes |
completeResolutionRun() |
Reset _requestIteration to 1 between compliance passes |
Framework calls completeResolutionRun() at end of _validateCompliance.
| Constant | Name | Source |
|---|---|---|
ITEM_NAME |
name |
itemNameSelector text (if selector non-empty) |
ITEM_PROCESSED_ONCE |
processed_once |
false until first compliance completes |
Access in app code via this._get(item, ITEM_NAME) (framework protected helper).
Use when compact search layouts omit tags on tiles, or duration/rating exists only on the detail page.
Cost: extra HTTP work and cumulative delay (requestDelay * iteration). Prefer shallow reads when the DOM already exposes data.
Filter helpers such as _addItemTagAttribute and _addItemDurationRangeFilter register attributes automatically.
Next in stack: Framework core (optional Paginator / Subscriptions Loader before core).