Created
September 22, 2024 12:00
-
-
Save thewh1teagle/49c2a2cc3c2ee7022eed4f0d6a2dc968 to your computer and use it in GitHub Desktop.
Insert links in yad2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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