Last active
December 24, 2015 20:18
-
-
Save hallvors/6856362 to your computer and use it in GitHub Desktop.
This strips out HREF, VALUE and SRC attributes and comment nodes to be able to serialize the DOM and compare mostly the structure. This helps because HREF, VALUE and SRC tends to contain session identifiers with random data that give false positives when trying to diff the HTML code.
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
(function(){ | |
function removeAttr(attr){ | |
var xpElms = document.evaluate('//*[@'+attr+']', document.documentElement, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE , null ); | |
var elm; | |
for(var i=0; elm = xpElms.snapshotItem(i); i++){ | |
elm.removeAttribute(attr) | |
} | |
} | |
removeAttr('href'); | |
removeAttr('src'); | |
removeAttr('value'); | |
// remove <!-- comment --> and text nodes | |
var xpElms = document.evaluate('//comment()|//text()', document.documentElement, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE , null ); | |
for(var i=0; elm = xpElms.snapshotItem(i); i++){ | |
if(!(elm.parentElement.tagName in {'SCRIPT':1,'STYLE':1})) | |
elm.parentElement.removeChild(elm) | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment