Here is a prompt designed to give an LLM all the necessary information to accurately recreate the provided YouTube Shorts channel blocker code, focusing on the current functionality and UI constraints.
"You are an expert JavaScript developer tasked with recreating a Tampermonkey/Greasemonkey UserScript designed to filter YouTube Shorts videos. The goal is to enforce a binary block/allow list based purely on the channel name.
The final script must adhere strictly to the following Functionality, Data Structure, and User Interface (UI) requirements:
- Type: JavaScript for Tampermonkey/Greasemonkey.
- Match: Must target
https://www.youtube.com/*. - Grant:
none. - Engine: Use a
MutationObserveron the#shorts-inner-containerordocument.bodyand asetIntervalfallback to detect when a new video (ytd-reel-video-renderer[is-active]) loads.
- Data Structure: The block list must be an Array of Objects (
BlockedChannelsWithTime), where each object contains{ name: string, blockedAt: number }. Thenamemust be stored in lowercase. - Storage: Use
chrome.storage.local(or equivalent browser storage) to save and load the block list data persistently using the keyChannelBlockerList. - Fast Lookup: Maintain a separate
Set(BlockedChannelNamesFastLookup) in memory for quick lookups when checking if a channel is blocked.
- Implement a robust function (
getActiveChannelName) to extract the channel name (e.g., 'mianxiwei7406' from@mianxiwei7406) from the active video player. Prioritize selectors that target the link near the subscribe button, such asa.yt-core-attributed-string__link[href*="/shorts"]. - If the video is detected as 'Sponsored' (using
.yt-badge-shape__text), the script must immediately trigger a skip.
The script must inject a minimalist overlay (#channel-blocker-overlay) in the fixed position (top: 70px, right: 20px). The overlay must contain:
| Element | Location | Function/Appearance |
|---|---|---|
| Header | Top row | Displays 'CHANNEL FILTER' and the Manage List Button (π icon). |
| Block Button | Directly before the channel name. | Icon: β (Unicode Stop Sign). |
| Channel Name | In the main body, next to the Block Button. | Displays @channelName. |
| Feedback | Hidden layer | Displays brief messages (e.g., 'Blocked: X Channel'). |
- Click Block Button (β):
- Add the current channel name (lowercase) and current timestamp to the
BlockedChannelsWithTimearray and update theBlockedChannelNamesFastLookupset. - Immediately call
triggerSkipToNextVideo()(with a 400ms delay). - Update the UI button state to Blocked.
- Add the current channel name (lowercase) and current timestamp to the
- Video Load (Engine): When a new video loads:
- Check if the channel is in the block list.
- If Blocked, the UI must update to the Blocked State (Red text/button, disabled click).
- If Blocked, the script must NOT automatically trigger a skip or change the video's opacity, as skipping is handled solely by the button click.
| State | Block Button Style | Channel Name Style | Button Interaction |
|---|---|---|---|
| Allowed | Background: #222, Border: #444, Opacity: 1. |
Color: #a855f7 (Purple) |
Enabled (pointer-events: auto) |
| Blocked | Background: #600 (Dark Red), Border: #f87171 (Red), Opacity: 0.7. |
Color: #f87171 (Red) |
Disabled (pointer-events: none) |
- The π button must open a modal (
#blocker-list-modal). - The modal must list all blocked channels (
BlockedChannelsWithTime), sorted byblockedAtin descending order (most recent blocks first). - Each list item must include a "Re-Allow" button that calls
unblockChannel, removes the channel from storage, and visually updates the list."