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>
|
||||
<div id="app">
|
||||
<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="status" class="status" style="min-height:16px;"></div>
|
||||
<div id="btn-row" class="btn-row" style="display:none;">
|
||||
|
||||
+14
-8
@@ -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 () => {
|
||||
setStatus('Scanning tabs…');
|
||||
|
||||
@@ -97,8 +97,7 @@ findBtn.addEventListener('click', async () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Limit to 4 tabs
|
||||
const tabsToScan = validTabs.slice(0, 4);
|
||||
const tabsToScan = validTabs;
|
||||
setStatus(`Scanning ${tabsToScan.length} tab(s)…`);
|
||||
|
||||
try {
|
||||
@@ -114,18 +113,25 @@ findBtn.addEventListener('click', async () => {
|
||||
return { videos, videoCount, sources, audios };
|
||||
};
|
||||
const results = await Promise.all(
|
||||
tabsToScan.map(t => chrome.scripting.executeScript({
|
||||
tabsToScan.map(async t => {
|
||||
try {
|
||||
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
|
||||
// Each tab's results array is grouped with its tab title
|
||||
const tabResults = tabsToScan.map((tab, i) => ({
|
||||
tabTitle: tab.title || 'Unknown',
|
||||
frames: results[i]?.filter(Boolean) || [],
|
||||
}));
|
||||
})).filter(g => g.frames.length > 0);
|
||||
const scanned = tabResults.length;
|
||||
|
||||
const seen = new Map();
|
||||
let totalFound = 0;
|
||||
@@ -152,7 +158,7 @@ findBtn.addEventListener('click', async () => {
|
||||
[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 })));
|
||||
btnRow.style.display = 'flex';
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user