allow scanning all tabs instead of limiting to 4
- Remove the hardcoded 4-tab limit in the find-videos flow - Add per-tab try/catch so inaccessible tabs are skipped gracefully - Filter out tabs that produced no frames from the dedup pipeline - Update button label and status messages accordingly
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<h1>Goon Plugin</h1>
|
<h1>Goon Plugin</h1>
|
||||||
<button id="find-btn">Find Videos (4 tabs)</button>
|
<button id="find-btn">Find Videos (all tabs)</button>
|
||||||
<div id="video-list" class="video-list" style="display:none;"></div>
|
<div id="video-list" class="video-list" style="display:none;"></div>
|
||||||
<div id="status" class="status" style="min-height:16px;"></div>
|
<div id="status" class="status" style="min-height:16px;"></div>
|
||||||
<div id="btn-row" class="btn-row" style="display:none;">
|
<div id="btn-row" class="btn-row" style="display:none;">
|
||||||
|
|||||||
+16
-10
@@ -75,7 +75,7 @@ function showActions() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* === "Find Videos" — scan up to 4 tabs === */
|
/* === "Find Videos" — scan all tabs in the window === */
|
||||||
findBtn.addEventListener('click', async () => {
|
findBtn.addEventListener('click', async () => {
|
||||||
setStatus('Scanning tabs…');
|
setStatus('Scanning tabs…');
|
||||||
|
|
||||||
@@ -97,8 +97,7 @@ findBtn.addEventListener('click', async () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limit to 4 tabs
|
const tabsToScan = validTabs;
|
||||||
const tabsToScan = validTabs.slice(0, 4);
|
|
||||||
setStatus(`Scanning ${tabsToScan.length} tab(s)…`);
|
setStatus(`Scanning ${tabsToScan.length} tab(s)…`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -114,18 +113,25 @@ findBtn.addEventListener('click', async () => {
|
|||||||
return { videos, videoCount, sources, audios };
|
return { videos, videoCount, sources, audios };
|
||||||
};
|
};
|
||||||
const results = await Promise.all(
|
const results = await Promise.all(
|
||||||
tabsToScan.map(t => chrome.scripting.executeScript({
|
tabsToScan.map(async t => {
|
||||||
target: { tabId: t.id, allFrames: true },
|
try {
|
||||||
func: scrapeFn,
|
return await chrome.scripting.executeScript({
|
||||||
}))
|
target: { tabId: t.id, allFrames: true },
|
||||||
|
func: scrapeFn,
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
console.warn('[goon] skipping tab', t.id, ':', t.url);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// Dedup across all tabs by (src+poster) key
|
// Dedup across all tabs by (src+poster) key
|
||||||
// Each tab's results array is grouped with its tab title
|
|
||||||
const tabResults = tabsToScan.map((tab, i) => ({
|
const tabResults = tabsToScan.map((tab, i) => ({
|
||||||
tabTitle: tab.title || 'Unknown',
|
tabTitle: tab.title || 'Unknown',
|
||||||
frames: results[i]?.filter(Boolean) || [],
|
frames: results[i]?.filter(Boolean) || [],
|
||||||
}));
|
})).filter(g => g.frames.length > 0);
|
||||||
|
const scanned = tabResults.length;
|
||||||
|
|
||||||
const seen = new Map();
|
const seen = new Map();
|
||||||
let totalFound = 0;
|
let totalFound = 0;
|
||||||
@@ -152,7 +158,7 @@ findBtn.addEventListener('click', async () => {
|
|||||||
[TAGGED_KEY]: items.map(v => v.tab),
|
[TAGGED_KEY]: items.map(v => v.tab),
|
||||||
});
|
});
|
||||||
|
|
||||||
setStatus(`Found ${items.length} video(s) across ${tabsToScan.length} tab(s).`);
|
setStatus(`Found ${items.length} video(s) across ${scanned} tab(s).`);
|
||||||
renderList(items.map(v => ({ url: v.url, label: v.tab })));
|
renderList(items.map(v => ({ url: v.url, label: v.tab })));
|
||||||
btnRow.style.display = 'flex';
|
btnRow.style.display = 'flex';
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user