moderator-toolbox-nxg-for-reddit / dom/shreddit/things

dom/shreddit/things

Functions

collectMatches()

collectMatches(root, selector): Element[]

Defined in: extension/data/dom/shreddit/things.ts:22

Collects root itself (when it matches) plus all matching descendants. The standard enumeration idiom for processing MutationObserver addedNodes, where the added node may itself be the element of interest or contain them.

Parameters

root

Element | Document

selector

string

Returns

Element[]


findCommentFlatListTargets()

findCommentFlatListTargets(root): CommentFlatListTarget[]

Defined in: extension/data/dom/shreddit/things.ts:235

Finds shreddit-comment-action-row elements that need a thingFlatListActions slot injected. Returns one result per action row that exposes a <mod-content-actions slot="mod-content-actions"> child and does not already have a toolbox-flat-list-slot injected immediately after it.

Parameters

root

Element

Returns

CommentFlatListTarget[]


findPostFlatListTargets()

findPostFlatListTargets(root): PostFlatListTarget[]

Defined in: extension/data/dom/shreddit/things.ts:215

Finds shreddit-post elements that need a thingFlatListActions slot injected. Returns one result per post that exposes a <mod-content-actions slot="mod-content-actions"> child (Reddit’s signal that the post is mod-actionable) and does not already have a toolbox-flat-list-slot.

Parameters

root

Element

Returns

PostFlatListTarget[]


flatListThingContainer()

flatListThingContainer(thing): Element

Defined in: extension/data/dom/shreddit/things.ts:166

Returns the element a thing’s toolbox-flat-list-slot should be appended to so the Toolbox mod-action row renders on its own line below the post/comment rather than crammed into Reddit’s width-constrained native action bar: the thing’s existing toolbox-thing-slot container when one is present (keeping Toolbox’s thing-level UI grouped), otherwise the thing element itself. Both render in the thing’s default-slot area, the same place the proven-clickable domain-tag button already sits.

Parameters

thing

Element

Returns

Element


getNativeApproveButton()

getNativeApproveButton(thing): Element | null

Defined in: extension/data/dom/shreddit/things.ts:80

Returns the native shreddit approve button inside a thing element, mirroring getNativeRemoveButton: the mod-action-button custom element first, then the test-id/item-id button fallbacks used by other shreddit surfaces. Used to relocate the native approve control into the Toolbox flat-list action group so it sits alongside the Toolbox remove button. Returns null when the thing has no native approve control (e.g. an item that hasn’t been removed/reported, where Reddit shows no approve).

Parameters

thing

Element

Returns

Element | null


getNativeRemoveButton()

getNativeRemoveButton(thing): Element | null

Defined in: extension/data/dom/shreddit/things.ts:64

Returns the native shreddit remove button inside a thing element, trying the mod-action custom element first and falling back to the test-id/item-id buttons used by other shreddit surfaces (including the overflow menu’s shadow DOM). Returns null when the thing has no native remove control.

Parameters

thing

Element

Returns

Element | null


getShredditPostDomain()

getShredditPostDomain(postEl): string | null

Defined in: extension/data/dom/shreddit/things.ts:279

Returns the domain of a shreddit-post element, in the same format used by old Reddit’s domain tagger: "imgur.com" for link posts, "self.subredditname" for self posts.

Reads content-href - for link posts this is the external URL; for self posts it is the reddit.com permalink, which we detect by hostname to return the self.X form.

A leading www. is stripped from link domains so the result matches old Reddit’s display domain (e.g. nytimes.com, not www.nytimes.com). Keeping the two platforms in the same format means a tag created on one matches on the other, and approval/removal stats are tallied against a single domain key rather than split across www/non-www variants.

Returns null when the subreddit name is unavailable.

Parameters

postEl

Element

Returns

string | null


getThingContext()

getThingContext(thing): ThingContext | null

Defined in: extension/data/dom/shreddit/things.ts:42

Extracts the fullname, subreddit, and kind from a shreddit thing element (shreddit-comment, shreddit-post, or mod-queue-list-item). Returns null when either identifying attribute is missing.

Parameters

thing

Element

Returns

ThingContext | null


getThingFromDescendant()

getThingFromDescendant(element): Element | null

Defined in: extension/data/dom/shreddit/things.ts:11

Returns the nearest shreddit-comment, shreddit-post, or mod-queue-list-item ancestor of an element, or null. Equivalent to oldReddit.getThingFromDescendant for Shreddit’s custom-element DOM.

Parameters

element

Element

Returns

Element | null


getThings()

getThings(container?): Element[]

Defined in: extension/data/dom/shreddit/things.ts:120

Returns all div.thing elements within a container. Used for content rendered via old-Reddit-style helpers (e.g. profile overlay, history views).

Parameters

container?

Element | Document

Returns

Element[]


getThingSubreddit()

getThingSubreddit(thing): string | null

Defined in: extension/data/dom/shreddit/things.ts:127

Returns the data-subreddit attribute of a thing element rendered via old-Reddit-style helpers.

Parameters

thing

Element

Returns

string | null


isThingRemoved()

isThingRemoved(el): boolean

Defined in: extension/data/dom/shreddit/things.ts:136

Returns true when a shreddit thing element has been removed. Checks the legacy removed attribute, item-state="REMOVED", and moderation-verdict="MOD_REMOVED".

Parameters

el

Element

Returns

boolean


stripSubredditPrefix()

stripSubredditPrefix(prefixed): string

Defined in: extension/data/dom/shreddit/things.ts:154

Strips the r/ prefix from a subreddit-prefixed-name attribute value. Returns the bare subreddit name, or an empty string when the input is absent.

Parameters

prefixed

string

Returns

string



suppressNativeOverflowModActions()

suppressNativeOverflowModActions(thing): () => void

Defined in: extension/data/dom/shreddit/things.ts:103

Removes the should-include-mod-actions boolean attribute from a thing’s lazy overflow (…) menu so Reddit renders that menu WITHOUT the native mod actions (approve / remove / remove-as-spam / lock / distinguish / …), while keeping the non-mod entries (share, save, award, …). Toolbox surfaces those mod actions inline in the flat-list row instead, so the native copies would only duplicate them.

The overflow menu is lazy-loaded (shreddit-async-loader -> unpacking-overflow-menu), so it may not exist yet when a feed item first mounts. The shared mutation pass re-processes added nodes, so a freshly-inserted menu gets stripped on a later call; the menu carries the attribute from the moment it is inserted (verified in captured feed HTML), so stripping it before the user opens the menu keeps the mod actions from ever rendering. Safe to call repeatedly.

Parameters

thing

Element

A shreddit-post, shreddit-comment, or shreddit-comment-action-row element.

Returns

A cleanup that restores the attribute on every menu it stripped.

() => void

Interfaces

CommentFlatListTarget

Defined in: extension/data/dom/shreddit/things.ts:191

Data extracted from a shreddit-comment that needs a thingFlatListActions slot.

Properties

actionRow

actionRow: Element

Defined in: extension/data/dom/shreddit/things.ts:198

The shreddit-comment-action-row to insert the slot immediately before. Comments nest (a reply is a descendant shreddit-comment of its parent), so appending to the end of the shreddit-comment would place the row below the entire reply tree. Inserting right before the action row keeps it above this comment’s action bar, ahead of any nested replies.

comment

comment: Element

Defined in: extension/data/dom/shreddit/things.ts:200

The enclosing shreddit-comment (used to suppress its native overflow mod actions).

isRemoved

isRemoved: boolean

Defined in: extension/data/dom/shreddit/things.ts:206

postId

postId: string

Defined in: extension/data/dom/shreddit/things.ts:204

Post fullname (e.g. t3_abc123).

subreddit

subreddit: string

Defined in: extension/data/dom/shreddit/things.ts:205

thingId

thingId: string

Defined in: extension/data/dom/shreddit/things.ts:202

Comment fullname (e.g. t1_abc123).


PostFlatListTarget

Defined in: extension/data/dom/shreddit/things.ts:181

Data extracted from a shreddit-post that needs a thingFlatListActions slot.

Properties

isRemoved

isRemoved: boolean

Defined in: extension/data/dom/shreddit/things.ts:187

post

post: Element

Defined in: extension/data/dom/shreddit/things.ts:183

The shreddit-post element to append the slot to (via flatListThingContainer).

subreddit

subreddit: string

Defined in: extension/data/dom/shreddit/things.ts:186

thingId

thingId: string

Defined in: extension/data/dom/shreddit/things.ts:185

Post fullname (e.g. t3_abc123).


ThingContext

Defined in: extension/data/dom/shreddit/things.ts:29

Identifying context extracted from a shreddit thing element.

Properties

isComment

isComment: boolean

Defined in: extension/data/dom/shreddit/things.ts:34

subreddit

subreddit: string

Defined in: extension/data/dom/shreddit/things.ts:33

Bare subreddit name without the r/ prefix.

thingId

thingId: string

Defined in: extension/data/dom/shreddit/things.ts:31

Thing fullname (e.g. t3_abc123 or t1_abc123).