Skip to content

Instantly share code, notes, and snippets.

@louisbarclay
Created February 23, 2021 10:32
Show Gist options
  • Save louisbarclay/7a43a37070ac573b8c657bb15c4da2f7 to your computer and use it in GitHub Desktop.
Save louisbarclay/7a43a37070ac573b8c657bb15c4da2f7 to your computer and use it in GitHub Desktop.
<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