Compare commits
No commits in common. "8e9e0e0b76e7ec73e404e6f73ac1d27da34a96d7" and "a4f2f5c60bae66954c22679f3d050801b32b78c1" have entirely different histories.
8e9e0e0b76
...
a4f2f5c60b
243
content.js
243
content.js
@ -4,9 +4,7 @@ let whitelistHandles = [];
|
||||
let debugEnabled = false;
|
||||
// In-memory index of known member-only videos.
|
||||
const memberOnlyIndex = new Map(); // id -> { channelKey, hidden }
|
||||
const sharedIndex = new Map(); // stableId -> meta for cross-tab HUD (hidden only)
|
||||
const sharedSeenIndex = new Map(); // stableId -> meta for all seen videos
|
||||
const sharedMemberIndex = new Map(); // stableId -> meta for member-only videos
|
||||
const sharedIndex = new Map(); // stableId -> meta for cross-tab HUD
|
||||
// Data-* attribute prefix for DOM tags.
|
||||
const DATA_PREFIX = "chipperfluff-nobs"; // nobs = "no-bs" (member-only videos)
|
||||
const HUD_DOT_ID = `${DATA_PREFIX}-hud-dot`;
|
||||
@ -15,13 +13,9 @@ let generatedIdCounter = 0;
|
||||
let hudDirty = false;
|
||||
let lastHudSignature = "";
|
||||
const STORAGE_KEY = "memberOnlyHidden";
|
||||
const STORAGE_KEY_SEEN = "memberOnlySeen";
|
||||
const STORAGE_KEY_MEMBER = "memberOnlyDetected";
|
||||
const DEFAULT_MAX_ARCHIVE = 2000;
|
||||
const DEFAULT_MAX_ARCHIVE = 500;
|
||||
const MAX_SNAPSHOT_CHARS = 20000;
|
||||
let persistHiddenTimer = null;
|
||||
let persistSeenTimer = null;
|
||||
let persistMemberTimer = null;
|
||||
let persistTimer = null;
|
||||
let contextInvalidated = false;
|
||||
let hudFlashTimer = null;
|
||||
|
||||
@ -318,18 +312,6 @@ chrome.storage.onChanged.addListener(changes => {
|
||||
items.forEach(item => sharedIndex.set(item.id, item));
|
||||
updateHudDot();
|
||||
}
|
||||
if (changes[STORAGE_KEY_SEEN]) {
|
||||
const items = changes[STORAGE_KEY_SEEN].newValue || [];
|
||||
sharedSeenIndex.clear();
|
||||
items.forEach(item => sharedSeenIndex.set(item.id, item));
|
||||
updateHudDot();
|
||||
}
|
||||
if (changes[STORAGE_KEY_MEMBER]) {
|
||||
const items = changes[STORAGE_KEY_MEMBER].newValue || [];
|
||||
sharedMemberIndex.clear();
|
||||
items.forEach(item => sharedMemberIndex.set(item.id, item));
|
||||
updateHudDot();
|
||||
}
|
||||
if (changes.whitelist || changes.debug) {
|
||||
loadSettings();
|
||||
}
|
||||
@ -339,8 +321,7 @@ chrome.storage.onChanged.addListener(changes => {
|
||||
|
||||
// Detect member-only videos and tag them for future updates.
|
||||
function process(root = document) {
|
||||
const bypassHide = isWhitelistedChannelPage();
|
||||
scanAllVideos(root);
|
||||
if (isWhitelistedChannelPage()) return;
|
||||
const badges = root.querySelectorAll("badge-shape");
|
||||
|
||||
badges.forEach(badge => {
|
||||
@ -381,18 +362,6 @@ function process(root = document) {
|
||||
thumb
|
||||
});
|
||||
hudDirty = true;
|
||||
updateMemberIndex({
|
||||
stableId,
|
||||
channelKey,
|
||||
channelLabel: channel,
|
||||
channelUrl
|
||||
});
|
||||
updateSeenIndex({
|
||||
stableId,
|
||||
channelKey,
|
||||
channelLabel: channel,
|
||||
channelUrl
|
||||
});
|
||||
} else {
|
||||
// Fill missing metadata as it becomes available.
|
||||
if (!existing.title && title) existing.title = title;
|
||||
@ -404,18 +373,6 @@ function process(root = document) {
|
||||
if (!existing.snapshot) existing.snapshot = safeSnapshot(video);
|
||||
updateSharedIndex(existing, true);
|
||||
}
|
||||
updateMemberIndex({
|
||||
stableId: existing.stableId,
|
||||
channelKey: existing.channelKey,
|
||||
channelLabel: existing.channelLabel,
|
||||
channelUrl: existing.channelUrl
|
||||
});
|
||||
updateSeenIndex({
|
||||
stableId: existing.stableId,
|
||||
channelKey: existing.channelKey,
|
||||
channelLabel: existing.channelLabel,
|
||||
channelUrl: existing.channelUrl
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -429,7 +386,7 @@ function process(root = document) {
|
||||
debugLog("Whitelisted:", whitelisted);
|
||||
debugGroupEnd();
|
||||
|
||||
if (!whitelisted && !bypassHide) {
|
||||
if (!whitelisted) {
|
||||
if (id && memberOnlyIndex.has(id)) {
|
||||
const meta = memberOnlyIndex.get(id);
|
||||
if (!meta.hidden) flashHudDot();
|
||||
@ -453,27 +410,6 @@ function process(root = document) {
|
||||
updateHudDot();
|
||||
}
|
||||
|
||||
function scanAllVideos(root) {
|
||||
const selector =
|
||||
"ytd-rich-item-renderer, ytd-video-renderer, ytd-grid-video-renderer";
|
||||
const videos = root.querySelectorAll(selector);
|
||||
const rootIsVideo =
|
||||
root instanceof HTMLElement && root.matches && root.matches(selector);
|
||||
const allVideos = rootIsVideo ? [root, ...videos] : Array.from(videos);
|
||||
|
||||
allVideos.forEach(video => {
|
||||
const videoMeta = getVideoMeta(video);
|
||||
if (!videoMeta.videoId) return;
|
||||
const channelInfo = getChannelInfo(video);
|
||||
updateSeenIndex({
|
||||
stableId: videoMeta.videoId,
|
||||
channelKey: channelInfo.key,
|
||||
channelLabel: channelInfo.label,
|
||||
channelUrl: channelInfo.url
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Apply whitelist to already-tagged member-only videos.
|
||||
function updateKnownVisibility() {
|
||||
if (isWhitelistedChannelPage()) {
|
||||
@ -726,8 +662,6 @@ function ensureHudDot() {
|
||||
}
|
||||
|
||||
function updateHudDot() {
|
||||
if (contextInvalidated || !document?.body) return;
|
||||
try {
|
||||
const dot = ensureHudDot();
|
||||
const panel = document.getElementById(HUD_PANEL_ID);
|
||||
const total = sharedIndex.size;
|
||||
@ -747,9 +681,6 @@ function updateHudDot() {
|
||||
hudDirty = false;
|
||||
lastHudSignature = signature;
|
||||
}
|
||||
} catch (error) {
|
||||
contextInvalidated = true;
|
||||
}
|
||||
}
|
||||
|
||||
function flashHudDot() {
|
||||
@ -786,52 +717,10 @@ function updateSharedIndex(meta, hidden) {
|
||||
schedulePersistSharedIndex();
|
||||
}
|
||||
|
||||
function updateSeenIndex(meta) {
|
||||
if (!meta.stableId) return;
|
||||
const existing = sharedSeenIndex.get(meta.stableId);
|
||||
if (!existing) {
|
||||
sharedSeenIndex.set(meta.stableId, {
|
||||
id: meta.stableId,
|
||||
channelKey: meta.channelKey,
|
||||
channelLabel: meta.channelLabel,
|
||||
channelUrl: meta.channelUrl,
|
||||
lastSeen: Date.now()
|
||||
});
|
||||
schedulePersistSeenIndex();
|
||||
return;
|
||||
}
|
||||
existing.channelKey = meta.channelKey || existing.channelKey;
|
||||
existing.channelLabel = meta.channelLabel || existing.channelLabel;
|
||||
existing.channelUrl = meta.channelUrl || existing.channelUrl;
|
||||
existing.lastSeen = Date.now();
|
||||
schedulePersistSeenIndex();
|
||||
}
|
||||
|
||||
function updateMemberIndex(meta) {
|
||||
if (!meta.stableId) return;
|
||||
const existing = sharedMemberIndex.get(meta.stableId);
|
||||
if (!existing) {
|
||||
sharedMemberIndex.set(meta.stableId, {
|
||||
id: meta.stableId,
|
||||
channelKey: meta.channelKey,
|
||||
channelLabel: meta.channelLabel,
|
||||
channelUrl: meta.channelUrl,
|
||||
lastSeen: Date.now()
|
||||
});
|
||||
schedulePersistMemberIndex();
|
||||
return;
|
||||
}
|
||||
existing.channelKey = meta.channelKey || existing.channelKey;
|
||||
existing.channelLabel = meta.channelLabel || existing.channelLabel;
|
||||
existing.channelUrl = meta.channelUrl || existing.channelUrl;
|
||||
existing.lastSeen = Date.now();
|
||||
schedulePersistMemberIndex();
|
||||
}
|
||||
|
||||
function schedulePersistSharedIndex() {
|
||||
if (persistHiddenTimer) return;
|
||||
persistHiddenTimer = setTimeout(() => {
|
||||
persistHiddenTimer = null;
|
||||
if (persistTimer) return;
|
||||
persistTimer = setTimeout(() => {
|
||||
persistTimer = null;
|
||||
persistSharedIndex();
|
||||
}, 200);
|
||||
}
|
||||
@ -852,80 +741,13 @@ function persistSharedIndex() {
|
||||
});
|
||||
}
|
||||
|
||||
function schedulePersistSeenIndex() {
|
||||
if (persistSeenTimer) return;
|
||||
persistSeenTimer = setTimeout(() => {
|
||||
persistSeenTimer = null;
|
||||
persistSeenIndex();
|
||||
}, 200);
|
||||
}
|
||||
|
||||
function persistSeenIndex() {
|
||||
if (!chrome?.storage?.local || contextInvalidated) return;
|
||||
const items = Array.from(sharedSeenIndex.values());
|
||||
items.sort((a, b) => (b.lastSeen || 0) - (a.lastSeen || 0));
|
||||
chrome.storage.local.get({ maxArchive: DEFAULT_MAX_ARCHIVE }, data => {
|
||||
const maxArchive = Number(data.maxArchive);
|
||||
const max = Number.isFinite(maxArchive) ? maxArchive : DEFAULT_MAX_ARCHIVE;
|
||||
if (max < 0) {
|
||||
safeStorageSet({ [STORAGE_KEY_SEEN]: items });
|
||||
return;
|
||||
}
|
||||
safeStorageSet({ [STORAGE_KEY_SEEN]: items.slice(0, max) });
|
||||
});
|
||||
}
|
||||
|
||||
function schedulePersistMemberIndex() {
|
||||
if (persistMemberTimer) return;
|
||||
persistMemberTimer = setTimeout(() => {
|
||||
persistMemberTimer = null;
|
||||
persistMemberIndex();
|
||||
}, 200);
|
||||
}
|
||||
|
||||
function persistMemberIndex() {
|
||||
if (!chrome?.storage?.local || contextInvalidated) return;
|
||||
const items = Array.from(sharedMemberIndex.values());
|
||||
items.sort((a, b) => (b.lastSeen || 0) - (a.lastSeen || 0));
|
||||
chrome.storage.local.get({ maxArchive: DEFAULT_MAX_ARCHIVE }, data => {
|
||||
const maxArchive = Number(data.maxArchive);
|
||||
const max = Number.isFinite(maxArchive) ? maxArchive : DEFAULT_MAX_ARCHIVE;
|
||||
if (max < 0) {
|
||||
safeStorageSet({ [STORAGE_KEY_MEMBER]: items });
|
||||
return;
|
||||
}
|
||||
safeStorageSet({ [STORAGE_KEY_MEMBER]: items.slice(0, max) });
|
||||
});
|
||||
}
|
||||
|
||||
function loadStoredIndex() {
|
||||
if (!chrome?.storage?.local) return;
|
||||
chrome.storage.local.get(
|
||||
{ [STORAGE_KEY]: [], [STORAGE_KEY_SEEN]: [], [STORAGE_KEY_MEMBER]: [] },
|
||||
data => {
|
||||
sharedIndex.clear();
|
||||
data[STORAGE_KEY].forEach(item => sharedIndex.set(item.id, item));
|
||||
sharedSeenIndex.clear();
|
||||
data[STORAGE_KEY_SEEN].forEach(item => sharedSeenIndex.set(item.id, item));
|
||||
sharedMemberIndex.clear();
|
||||
data[STORAGE_KEY_MEMBER].forEach(item =>
|
||||
sharedMemberIndex.set(item.id, item)
|
||||
);
|
||||
if (sharedMemberIndex.size === 0 && sharedIndex.size > 0) {
|
||||
for (const item of sharedIndex.values()) {
|
||||
sharedMemberIndex.set(item.id, {
|
||||
id: item.id,
|
||||
channelKey: item.channelKey,
|
||||
channelLabel: item.channelLabel,
|
||||
channelUrl: item.channelUrl,
|
||||
lastSeen: item.lastSeen || Date.now()
|
||||
});
|
||||
}
|
||||
schedulePersistMemberIndex();
|
||||
}
|
||||
updateHudDot();
|
||||
}
|
||||
);
|
||||
chrome.storage.local.get({ [STORAGE_KEY]: [] }, data => {
|
||||
sharedIndex.clear();
|
||||
data[STORAGE_KEY].forEach(item => sharedIndex.set(item.id, item));
|
||||
updateHudDot();
|
||||
});
|
||||
}
|
||||
|
||||
function renderHudPanel(panel) {
|
||||
@ -967,9 +789,6 @@ function renderHudPanel(panel) {
|
||||
return;
|
||||
}
|
||||
|
||||
const totals = getSeenTotalsByCreator();
|
||||
const memberTotals = getMemberTotalsByCreator();
|
||||
|
||||
for (const [creator, items] of groups.entries()) {
|
||||
const details = document.createElement("details");
|
||||
details.className = `${DATA_PREFIX}-channel`;
|
||||
@ -980,10 +799,7 @@ function renderHudPanel(panel) {
|
||||
const label = items[0]?.channelLabel && items[0].channelLabel !== "(no channel)"
|
||||
? items[0].channelLabel
|
||||
: creator;
|
||||
const total = totals.get(creator) || items.length;
|
||||
const memberCount = memberTotals.get(creator) || 0;
|
||||
const percent = total > 0 ? Math.round((memberCount / total) * 100) : 0;
|
||||
summary.textContent = `${label} (${memberCount}/${total} known, ${percent}%)`;
|
||||
summary.textContent = `${label} (${items.length})`;
|
||||
details.appendChild(summary);
|
||||
|
||||
const list = document.createElement("div");
|
||||
@ -1024,38 +840,9 @@ function renderHudPanel(panel) {
|
||||
}
|
||||
}
|
||||
|
||||
function getSeenTotalsByCreator() {
|
||||
const totals = new Map();
|
||||
for (const meta of sharedSeenIndex.values()) {
|
||||
const key =
|
||||
meta.channelKey ||
|
||||
getChannelKeyFromData(meta.channelLabel, meta.channelUrl) ||
|
||||
"(unknown)";
|
||||
totals.set(key, (totals.get(key) || 0) + 1);
|
||||
}
|
||||
return totals;
|
||||
}
|
||||
|
||||
function getMemberTotalsByCreator() {
|
||||
const totals = new Map();
|
||||
for (const meta of sharedMemberIndex.values()) {
|
||||
const key =
|
||||
meta.channelKey ||
|
||||
getChannelKeyFromData(meta.channelLabel, meta.channelUrl) ||
|
||||
"(unknown)";
|
||||
totals.set(key, (totals.get(key) || 0) + 1);
|
||||
}
|
||||
return totals;
|
||||
}
|
||||
|
||||
function clearArchive() {
|
||||
sharedIndex.clear();
|
||||
sharedSeenIndex.clear();
|
||||
sharedMemberIndex.clear();
|
||||
safeStorageSet(
|
||||
{ [STORAGE_KEY]: [], [STORAGE_KEY_SEEN]: [], [STORAGE_KEY_MEMBER]: [] },
|
||||
() => updateHudDot()
|
||||
);
|
||||
safeStorageSet({ [STORAGE_KEY]: [] }, () => updateHudDot());
|
||||
}
|
||||
|
||||
function safeStorageSet(payload, callback) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user