/********************************************* * Description - Get all images in the current tab * Author - Vilyaem * *******************************************/ async function GetImagesFromTab() { const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); if (!tab || !tab.id || !tab.url.startsWith("http")) { alert("Not a valid tab."); return []; } return new Promise(resolve => { chrome.tabs.sendMessage(tab.id, { action: "GetImageURLs" }, (response) => { if (chrome.runtime.lastError || !response) { alert("Content script not available. Try refreshing the page."); return resolve([]); } resolve(response.urls || []); }); }); } /********************************************* * Description - Open all images in a new tab * Author - Vilyaem * *******************************************/ document.getElementById("open").addEventListener("click", async () => { const urls = await GetImagesFromTab(); if (urls.length === 0) return alert("No image URLs found."); urls.forEach(url => chrome.tabs.create({ url })); }); /********************************************* * Description - Download all images * Author - Vilyaem * *******************************************/ document.getElementById("download").addEventListener("click", async () => { const urls = await GetImagesFromTab(); if (urls.length === 0) return alert("No image URLs found."); urls.forEach(url => { chrome.downloads.download({ url }); }); });