console.log("NotSmug loaded..."); /********************************************* * Description - Get highest quality version of an image * Author - Vilyaem * *******************************************/ function Upgrade(url) { return url.replace(/(-[A-Z]\d+)?\.jpg/, '-X5.jpg'); } /********************************************* * Description - Get all image URLs possible * Author - Vilyaem * *******************************************/ function ExtractImages() { const allUrls = new Set(); /*extract image urls everywhere, they start with photos.smugmug.com*/ document.querySelectorAll('*').forEach(el => { /*attributes*/ ['src', 'href', 'data-src'].forEach(attr => { const val = el.getAttribute?.(attr); if (val && val.includes('photos.smugmug.com') && val.endsWith('.jpg')) { allUrls.add(Upgrade(val)); } }); const style = el.getAttribute?.('style') || ''; const matches = [...style.matchAll(/url\(["']?(https:\/\/photos\.smugmug\.com\/.*?\.jpg)["']?\)/g)]; matches.forEach(match => allUrls.add(Upgrade(match[1]))); }); /*scripts and styles*/ document.querySelectorAll('script, style').forEach(node => { const text = node.textContent; const matches = [...text.matchAll(/https:\/\/photos\.smugmug\.com\/.*?\.jpg/g)]; matches.forEach(match => allUrls.add(Upgrade(match[0]))); }); return Array.from(allUrls); } chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { if (request.action === "GetImageURLs") { sendResponse({ urls: ExtractImages() }); } });