Skip to content

Instantly share code, notes, and snippets.

@tamlyn
Created November 6, 2019 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamlyn/bd188c693a66f197eaad25ff7d57ab82 to your computer and use it in GitHub Desktop.
Save tamlyn/bd188c693a66f197eaad25ff7d57ab82 to your computer and use it in GitHub Desktop.
function removeOrigin(dom) {
let origin = window.location.origin;
let $internalElements = dom.querySelectorAll(`[href^="${origin}"],[src^="${origin}"]`);
for (let $el of $internalElements) {
const attr = $el.hasAttribute('href') ? 'href' : 'src';
const value = $el.getAttribute(attr);
$el.setAttribute(attr, value.replace(origin, ''));
}
return dom
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment