Created
February 23, 2021 10:32
-
-
Save louisbarclay/7a43a37070ac573b8c657bb15c4da2f7 to your computer and use it in GitHub Desktop.
This file contains 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
<script> | |
const originDomainAndPath = "view.flodesk.com/emails"; | |
const superMailerDomain = "mailer.super.so"; | |
async function createObserver() { | |
// Start observing the document | |
observeDoc(); | |
// Observer function | |
function observeDoc() { | |
const observer = new MutationObserver( | |
// You don't use any mutation info | |
// It's just a convenient trigger | |
() => { | |
searchAndReplace(); | |
} | |
); | |
// Observe entire document and childList to capture all mutations | |
observer.observe(document, { | |
childList: true, | |
subtree: true, | |
}); | |
} | |
} | |
function searchAndReplace() { | |
Array.from(document.getElementsByTagName("a")).forEach((element) => { | |
if (element.href.includes(originDomainAndPath)) { | |
console.log(element.href); | |
element.href = element.href.replace( | |
originDomainAndPath, | |
superMailerDomain | |
); | |
} | |
}); | |
} | |
searchAndReplace(); | |
createObserver(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment