|
|
@@ -4,6 +4,7 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
const STORAGE_KEY = 'goon_videos';
|
|
|
|
const STORAGE_KEY = 'goon_videos';
|
|
|
|
|
|
|
|
const TAGGED_KEY = 'goon_tagged';
|
|
|
|
|
|
|
|
|
|
|
|
const findBtn = document.getElementById('find-btn');
|
|
|
|
const findBtn = document.getElementById('find-btn');
|
|
|
|
const clearBtn = document.getElementById('clear-btn');
|
|
|
|
const clearBtn = document.getElementById('clear-btn');
|
|
|
@@ -20,27 +21,30 @@ function setStatus(msg) {
|
|
|
|
console.log('[goon]', msg);
|
|
|
|
console.log('[goon]', msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Load the current video list from storage. */
|
|
|
|
/** Load the current video list and tags from storage. */
|
|
|
|
function loadVideos() {
|
|
|
|
function loadVideos() {
|
|
|
|
return chrome.storage.local.get(STORAGE_KEY).then(data => data[STORAGE_KEY] || []);
|
|
|
|
return chrome.storage.local.get([STORAGE_KEY, TAGGED_KEY]).then(data => ({
|
|
|
|
|
|
|
|
urls: data[STORAGE_KEY] || [],
|
|
|
|
|
|
|
|
tags: data[TAGGED_KEY] || [],
|
|
|
|
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Render the video list UI from stored URLs. */
|
|
|
|
/** Render the video list UI from stored {url, label} objects. */
|
|
|
|
function renderList(urls) {
|
|
|
|
function renderList(items) {
|
|
|
|
listEl.innerHTML = '';
|
|
|
|
listEl.innerHTML = '';
|
|
|
|
if (!urls || urls.length === 0) {
|
|
|
|
if (!items || items.length === 0) {
|
|
|
|
listEl.style.display = 'none';
|
|
|
|
listEl.style.display = 'none';
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
listEl.style.display = 'block';
|
|
|
|
listEl.style.display = 'block';
|
|
|
|
|
|
|
|
|
|
|
|
for (const url of urls) {
|
|
|
|
for (const item of items) {
|
|
|
|
const item = document.createElement('a');
|
|
|
|
const link = document.createElement('a');
|
|
|
|
item.className = 'video-item';
|
|
|
|
link.className = 'video-item';
|
|
|
|
item.href = url;
|
|
|
|
link.href = item.url;
|
|
|
|
item.textContent = url;
|
|
|
|
link.textContent = item.label ? `${item.label}: ${item.url}` : item.url;
|
|
|
|
item.target = '_blank';
|
|
|
|
link.target = '_blank';
|
|
|
|
listEl.appendChild(item);
|
|
|
|
listEl.appendChild(link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Copy all URLs button
|
|
|
|
// Copy all URLs button
|
|
|
@@ -48,6 +52,7 @@ function renderList(urls) {
|
|
|
|
copyBtn.className = 'copy-btn';
|
|
|
|
copyBtn.className = 'copy-btn';
|
|
|
|
copyBtn.textContent = 'Copy All URLs';
|
|
|
|
copyBtn.textContent = 'Copy All URLs';
|
|
|
|
copyBtn.addEventListener('click', () => {
|
|
|
|
copyBtn.addEventListener('click', () => {
|
|
|
|
|
|
|
|
const urls = items.map(v => v.url);
|
|
|
|
navigator.clipboard.writeText(urls.join('\n')).then(() => {
|
|
|
|
navigator.clipboard.writeText(urls.join('\n')).then(() => {
|
|
|
|
copyBtn.textContent = 'Copied!';
|
|
|
|
copyBtn.textContent = 'Copied!';
|
|
|
|
setTimeout(() => { copyBtn.textContent = 'Copy All URLs'; }, 1500);
|
|
|
|
setTimeout(() => { copyBtn.textContent = 'Copy All URLs'; }, 1500);
|
|
|
@@ -59,9 +64,10 @@ function renderList(urls) {
|
|
|
|
/** Show the main button row. */
|
|
|
|
/** Show the main button row. */
|
|
|
|
function showActions() {
|
|
|
|
function showActions() {
|
|
|
|
btnRow.style.display = 'flex';
|
|
|
|
btnRow.style.display = 'flex';
|
|
|
|
loadVideos().then(urls => {
|
|
|
|
loadVideos().then(({ urls, tags }) => {
|
|
|
|
if (urls.length > 0) {
|
|
|
|
if (urls.length > 0) {
|
|
|
|
renderList(urls);
|
|
|
|
const items = urls.map((url, i) => ({ url, label: tags[i] }));
|
|
|
|
|
|
|
|
renderList(items);
|
|
|
|
setStatus(`Using ${urls.length} video(s) from last search.`);
|
|
|
|
setStatus(`Using ${urls.length} video(s) from last search.`);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
setStatus('');
|
|
|
|
setStatus('');
|
|
|
@@ -69,82 +75,85 @@ function showActions() {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* === "Find Videos" — scan the current tab === */
|
|
|
|
/* === "Find Videos" — scan up to 4 tabs === */
|
|
|
|
findBtn.addEventListener('click', async () => {
|
|
|
|
findBtn.addEventListener('click', async () => {
|
|
|
|
setStatus('Scanning current tab…');
|
|
|
|
setStatus('Scanning tabs…');
|
|
|
|
|
|
|
|
|
|
|
|
const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
|
|
|
|
// Get all tabs in the current window
|
|
|
|
const tab = tabs[0];
|
|
|
|
const allTabs = await chrome.tabs.query({ currentWindow: true });
|
|
|
|
if (!tab || !tab.url) {
|
|
|
|
|
|
|
|
setStatus('Cannot access the current tab.');
|
|
|
|
// Filter out chrome/system pages
|
|
|
|
|
|
|
|
const validTabs = allTabs.filter(t =>
|
|
|
|
|
|
|
|
t.url &&
|
|
|
|
|
|
|
|
!t.url.startsWith('chrome://') &&
|
|
|
|
|
|
|
|
!t.url.startsWith('chrome-extension://') &&
|
|
|
|
|
|
|
|
!t.url.startsWith('edge://') &&
|
|
|
|
|
|
|
|
!t.url.startsWith('about:') &&
|
|
|
|
|
|
|
|
!t.url.startsWith('view-source:')
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (validTabs.length === 0) {
|
|
|
|
|
|
|
|
setStatus('No browsable tabs found.');
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Skip chrome-internal pages
|
|
|
|
// Limit to 4 tabs
|
|
|
|
if (tab.url.startsWith('chrome://') || tab.url.startsWith('chrome-extension://')
|
|
|
|
const tabsToScan = validTabs.slice(0, 4);
|
|
|
|
|| tab.url.startsWith('edge://') || tab.url.startsWith('about:')
|
|
|
|
setStatus(`Scanning ${tabsToScan.length} tab(s)…`);
|
|
|
|
|| tab.url.startsWith('view-source:')) {
|
|
|
|
|
|
|
|
setStatus('This page cannot be scanned.');
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// Check the main frame first, then iframes
|
|
|
|
// Execute scraping on all tabs in parallel
|
|
|
|
const results = await chrome.scripting.executeScript({
|
|
|
|
const scrapeFn = () => {
|
|
|
|
target: { tabId: tab.id, allFrames: true },
|
|
|
|
|
|
|
|
func: () => {
|
|
|
|
|
|
|
|
// Count both <video> and elements that might be video-like
|
|
|
|
|
|
|
|
const videos = Array.from(document.querySelectorAll('video')).map(v => ({
|
|
|
|
const videos = Array.from(document.querySelectorAll('video')).map(v => ({
|
|
|
|
src: v.currentSrc || v.src || null,
|
|
|
|
src: v.currentSrc || v.src || null,
|
|
|
|
poster: v.poster || null,
|
|
|
|
poster: v.poster || null,
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
const videoCount = videos.length;
|
|
|
|
const videoCount = videos.length;
|
|
|
|
|
|
|
|
|
|
|
|
// Also count <source> tags inside video elements (they point to actual media)
|
|
|
|
|
|
|
|
const sources = Array.from(document.querySelectorAll('video source[src]')).map(s => s.src);
|
|
|
|
const sources = Array.from(document.querySelectorAll('video source[src]')).map(s => s.src);
|
|
|
|
|
|
|
|
|
|
|
|
// Also check <audio> elements (might have videos inside too)
|
|
|
|
|
|
|
|
const audios = Array.from(document.querySelectorAll('audio')).length;
|
|
|
|
const audios = Array.from(document.querySelectorAll('audio')).length;
|
|
|
|
|
|
|
|
|
|
|
|
return { videos, videoCount, sources, audios };
|
|
|
|
return { videos, videoCount, sources, audios };
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
const results = await Promise.all(
|
|
|
|
|
|
|
|
tabsToScan.map(t => chrome.scripting.executeScript({
|
|
|
|
|
|
|
|
target: { tabId: t.id, allFrames: true },
|
|
|
|
|
|
|
|
func: scrapeFn,
|
|
|
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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) || [],
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
// With allFrames: true, results contains one entry per frame (main + iframes)
|
|
|
|
|
|
|
|
// Dedup by (src, poster) pair to avoid counting same video in multiple frames
|
|
|
|
|
|
|
|
const seen = new Map();
|
|
|
|
const seen = new Map();
|
|
|
|
let totalFound = 0;
|
|
|
|
let totalFound = 0;
|
|
|
|
let totalSources = 0;
|
|
|
|
for (const group of tabResults) {
|
|
|
|
let totalAudios = 0;
|
|
|
|
for (const r of group.frames) {
|
|
|
|
for (const r of results) {
|
|
|
|
|
|
|
|
if (!r.result) continue;
|
|
|
|
if (!r.result) continue;
|
|
|
|
console.log('[goon] frame:', r.frameId, 'videos:', r.result.videoCount, 'sources:', r.result.sources.length, 'audios:', r.result.audios);
|
|
|
|
|
|
|
|
for (const v of r.result.videos) {
|
|
|
|
for (const v of r.result.videos) {
|
|
|
|
totalFound++;
|
|
|
|
totalFound++;
|
|
|
|
const key = (v.src || '(empty)') + '||' + (v.poster || '(none)');
|
|
|
|
const key = (v.src || '(empty)') + '||' + (v.poster || '(none)');
|
|
|
|
if (!seen.has(key)) {
|
|
|
|
if (!seen.has(key)) {
|
|
|
|
seen.set(key, v);
|
|
|
|
seen.set(key, { url: v.src || v.poster || '', tab: group.tabTitle });
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log('[goon] video element:', 'src=', v.src, 'poster=', v.poster);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
totalAudios += r.result.audios;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const videoUrls = [...seen.values()].map(v => v.src || v.poster || '').filter(Boolean);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('[goon] ===== Found', totalFound, 'video elements, unique:', videoUrls.length, 'audio tags:', totalAudios);
|
|
|
|
const items = [...seen.values()];
|
|
|
|
console.log('[goon] URLs:', videoUrls);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Append to existing list (dedup to avoid same video from same page)
|
|
|
|
console.log('[goon] ===== Found', totalFound, 'video elements across', tabsToScan.length, 'tabs, unique:', items.length);
|
|
|
|
const existing = await chrome.storage.local.get(STORAGE_KEY);
|
|
|
|
|
|
|
|
const existingUrls = existing[STORAGE_KEY] || [];
|
|
|
|
|
|
|
|
const merged = [...existingUrls, ...videoUrls];
|
|
|
|
|
|
|
|
const deduped = [...new Set(merged)];
|
|
|
|
|
|
|
|
console.log('[goon] merged', existingUrls.length, '+', videoUrls.length, '→', deduped.length, 'unique total');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await chrome.storage.local.set({ [STORAGE_KEY]: deduped });
|
|
|
|
// Replace the entire list (fresh scan)
|
|
|
|
|
|
|
|
await chrome.storage.local.set({
|
|
|
|
|
|
|
|
[STORAGE_KEY]: items.map(v => v.url),
|
|
|
|
|
|
|
|
[TAGGED_KEY]: items.map(v => v.tab),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
setStatus(`Found ${videoUrls.length} video(s) in the current tab.`);
|
|
|
|
setStatus(`Found ${items.length} video(s) across ${tabsToScan.length} tab(s).`);
|
|
|
|
renderList(videoUrls);
|
|
|
|
renderList(items.map(v => ({ url: v.url, label: v.tab })));
|
|
|
|
btnRow.style.display = 'flex';
|
|
|
|
btnRow.style.display = 'flex';
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
setStatus(`Scan failed: ${e.message}`);
|
|
|
|
setStatus(`Scan failed: ${e.message}`);
|
|
|
@@ -154,20 +163,21 @@ findBtn.addEventListener('click', async () => {
|
|
|
|
|
|
|
|
|
|
|
|
/* === "Open Viewer" — launch the 2x2 grid === */
|
|
|
|
/* === "Open Viewer" — launch the 2x2 grid === */
|
|
|
|
openBtn.addEventListener('click', async () => {
|
|
|
|
openBtn.addEventListener('click', async () => {
|
|
|
|
const videos = await loadVideos();
|
|
|
|
const { urls, tags } = await loadVideos();
|
|
|
|
console.log('[goon] Open Viewer clicked, loaded from storage:', videos, 'count:', videos?.length);
|
|
|
|
console.log('[goon] Open Viewer clicked, loaded from storage:', urls, 'tags:', tags);
|
|
|
|
|
|
|
|
|
|
|
|
if (!videos || videos.length === 0) {
|
|
|
|
if (!urls || urls.length === 0) {
|
|
|
|
setStatus('No videos found. Click "Find Videos" first.');
|
|
|
|
setStatus('No videos found. Click "Find Videos" first.');
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Take the first 4 (viewer grid is 2x2)
|
|
|
|
// Take the first 4 (viewer grid is 2x2)
|
|
|
|
const ids = videos.slice(0, 4);
|
|
|
|
const videoUrls = urls.slice(0, 4);
|
|
|
|
console.log('[goon] opening viewer with', ids.length, 'video URLs:', ids);
|
|
|
|
const videoTags = tags ? tags.slice(0, 4) : [];
|
|
|
|
|
|
|
|
console.log('[goon] opening viewer with', videoUrls.length, 'video URLs:', videoUrls);
|
|
|
|
|
|
|
|
|
|
|
|
const id = 'goonViewer_' + Date.now();
|
|
|
|
const id = 'goonViewer_' + Date.now();
|
|
|
|
await chrome.storage.local.set({ [id]: ids });
|
|
|
|
await chrome.storage.local.set({ [id]: videoUrls });
|
|
|
|
|
|
|
|
|
|
|
|
// Verify write
|
|
|
|
// Verify write
|
|
|
|
const verify = await chrome.storage.local.get([id]);
|
|
|
|
const verify = await chrome.storage.local.get([id]);
|
|
|
@@ -175,13 +185,14 @@ openBtn.addEventListener('click', async () => {
|
|
|
|
|
|
|
|
|
|
|
|
await new Promise(r => setTimeout(r, 100));
|
|
|
|
await new Promise(r => setTimeout(r, 100));
|
|
|
|
|
|
|
|
|
|
|
|
const viewerUrl = chrome.runtime.getURL('viewer/viewer.html') + '?id=' + id;
|
|
|
|
const tagsParam = videoTags.length > 0 ? '&tags=' + encodeURIComponent(JSON.stringify(videoTags)) : '';
|
|
|
|
|
|
|
|
const viewerUrl = chrome.runtime.getURL('viewer/viewer.html') + '?id=' + id + tagsParam;
|
|
|
|
chrome.windows.create({ url: viewerUrl, width: 1400, height: 900 });
|
|
|
|
chrome.windows.create({ url: viewerUrl, width: 1400, height: 900 });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/* === "Clear" — reset the stored list === */
|
|
|
|
/* === "Clear" — reset the stored list === */
|
|
|
|
clearBtn.addEventListener('click', async () => {
|
|
|
|
clearBtn.addEventListener('click', async () => {
|
|
|
|
await chrome.storage.local.remove([STORAGE_KEY]);
|
|
|
|
await chrome.storage.local.remove([STORAGE_KEY, TAGGED_KEY]);
|
|
|
|
listEl.style.display = 'none';
|
|
|
|
listEl.style.display = 'none';
|
|
|
|
listEl.innerHTML = '';
|
|
|
|
listEl.innerHTML = '';
|
|
|
|
setStatus('');
|
|
|
|
setStatus('');
|
|
|
|