Skip to content

Instantly share code, notes, and snippets.

@thewh1teagle
Created September 22, 2024 12:00
Show Gist options
  • Save thewh1teagle/49c2a2cc3c2ee7022eed4f0d6a2dc968 to your computer and use it in GitHub Desktop.
Save thewh1teagle/49c2a2cc3c2ee7022eed4f0d6a2dc968 to your computer and use it in GitHub Desktop.
Insert links in yad2
function insertLinks() {
const products = document.querySelectorAll('div[data-product-endpoint]');
for (const product of products) {
var productUrl = product.getAttribute('data-product-endpoint');
var link = document.createElement('a');
link.href = productUrl;
link.innerHTML = product.outerHTML;
link.target = '_blank';
product.parentNode.insertBefore(link, product);
product.remove();
}
}
var debounceTimer;
function debounceInsertLinks() {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(insertLinks, 300);
}
insertLinks();
const observer = new MutationObserver(() => debounceInsertLinks());
observer.observe(document.body, { childList: true, subtree: true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment