Files
tool__scripts/browser-snippets/img.src-grabber__yandex.js
2026-07-09 01:05:56 +02:00

76 lines
2.2 KiB
JavaScript

let collectedImgURL = JSON.parse(localStorage.getItem('collectedImgURL')) || [];
function collectInitialHrefs(targetNode) {
const links = targetNode.querySelectorAll('a[href*="img_url"]');
links.forEach(link => {
if (!collectedImgURL.includes(link.href)) {
collectedImgURL.push(link.href);
localStorage.setItem('collectedImgURL', JSON.stringify(collectedImgURL));
console.log(`🙄 Snagged an initial img url: ${link.href}`);
}
});
}
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.addedNodes.forEach((addedNode) => {
if (addedNode.nodeType === Node.ELEMENT_NODE) {
const links = addedNode.querySelectorAll('a[href*="img_url"]');
links.forEach((link) => {
if (!collectedImgURL.includes(link.href)) {
collectedImgURL.push(link.href);
localStorage.setItem('collectedImgURL', JSON.stringify(collectedImgURL));
console.log(`🙄 Added href: ${link.href}`);
}
});
}
});
});
});
function downloadData(data, fileName, type = 'text/plain') {
const blob = new Blob([data], { type });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = fileName;
link.click();
URL.revokeObjectURL(url);
}
function waitForElement(selector, callback) {
if (document.querySelector(selector) != null) {
console.log("💠‍🌐 Target acquired. Commencing operation collect-hrefs.");
callback(document.querySelector(selector));
} else {
setTimeout(() => waitForElement(selector, callback), 500);
}
}
collectInitialHrefs(document.body);
const config = { childList: true, subtree: true };
observer.observe(document.body, config);
function stopObserving() {
observer.disconnect();
console.log("💠‍🌐 I've ceased surveillance. Here's what I've collected:");
const data = JSON.parse(localStorage.getItem('collectedImgURL')).join('\n');
console.log(data);
downloadData(data, 'images__yandex.txt');
}
function clearCollectedImgURL() {
localStorage.removeItem('collectedImgURL');
collectedImgURL = [];
console.log("💠‍🌐 Local storage cleared. The slate is wiped clean.");
}