Brazen Framework - Item Attributes Resolver

Item attributes resolution for the Brazen user scripts framework

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

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

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

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

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

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

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

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

Advertisement:

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

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

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

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

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

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

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

Advertisement:

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

Brazen Framework — Item Attribute Resolver (developer guide)

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

Module file: BrazenItemAttributeResolver.js · Class name: BrazenItemAttributesResolver (Greasy Fork @name uses plural Attributes).


When to use / when not to use

  • Use this module when your list tiles don’t contain enough information to filter reliably (tags, duration, rating, uploader, etc.) and the only source of truth is the item’s detail page.
  • Prefer shallow attributes whenever possible. Deep attributes are powerful but cost extra HTTP requests and add latency.
  • Don’t use deep attributes as a default on fast-scrolling infinite pages unless you throttle carefully and only deep-fetch the attributes you truly need.

Quick start

Most apps don’t instantiate this directly; the framework wires one for you using itemLinkSelector, itemDeepAnalysisSelector, and requestDelay from the BrazenFramework constructor config. You typically just register extractors or read values via the framework helper this._get(...).

// Shallow attribute: available on the tile.
this._itemAttributesResolver.addAttribute('uploader', (item) => {
  return item.find('.uploader').text().trim()
})

// Deep attribute: only available on the details page.
this._itemAttributesResolver.addDeepAttribute('tags', (sandbox) => {
  return sandbox.find('.tag').map((i, el) => $(el).text().trim()).get()
})

// In a filter/comply callback:
const uploader = this._get(item, 'uploader')

Constructor config

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.


Features

Storage model (where resolved values live)

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(' ', '_').


Attribute kinds (shallow, async, deep)

Shallow attributes run during the first compliance pass when the framework calls resolveAttributes(item).\n\n*Deep attributes* run lazily the first time get(item, name) is called and the value is missing.\n\n*Async attributes* are registered but not automatically invoked; use them for custom flows.

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

Shallow flow

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.

Deep flow

When get(item, 'tags') returns undefined and _hasDeepAttributes:

  1. Read href from item.find(itemLinkSelector).first().
  2. Utilities.sleep(_requestIteration * requestDelay) — throttles parallel fetches.
  3. Hidden sandbox #brazen-item-attributes-resolver-sandbox loads url + ' ' + itemDeepAnalysisSelector.
  4. Each deep extractor runs with sandbox jQuery as argument.
  5. onDeepAttributesResolution(item) fires.
  6. Sandbox emptied; _requestIteration incremented.

Manual injection

this._itemAttributesResolver.set(item, 'synthetic_tag', 'value')

Use in _onFirstHitBeforeCompliance when parsing tile DOM before filters run.


Public API

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.


Built-in framework attributes

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).


When to use deep attributes (practical guidance)

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).


Public API reference (index)

  • Registration: addAttribute, addAsyncAttribute, addDeepAttribute
  • Resolution: resolveAttributes, get, set, completeResolutionRun