-
-
Save joshuarrrr/e064886568b010a92495bcbae46865d7 to your computer and use it in GitHub Desktop.
Xpath twin finder
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
var mainTextStyles = [ | |
"color: #fff", | |
"background: #5ba745", | |
"font-weight: bold", | |
"display: block", | |
].join(";") | |
var errorStyles = [ | |
"color: #fff", | |
"background: #D05C4D", | |
"font-weight: bold", | |
"display: block", | |
].join(";") | |
var xpathStyles = [ | |
"color: #fff", | |
"background: #FBD481", | |
"font-weight: bold", | |
"display: block", | |
].join(";") | |
var elemStyles = [ | |
"color: #666", | |
"font-weight: bold" | |
].join(";") | |
var dividerStyles = [ | |
"color: #ccc", | |
].join(";") | |
if (typeof ParselyOverlay == "undefined") { | |
// console.log(`%c Parse.ly Overlay not detected`, errorStyles) | |
} else { | |
var isNotOnlyInXpath = (i, elem) => { | |
const xpathElem = ParselyOverlay.elemFromXPath(ParselyOverlay.getElementXPath(elem))[0] | |
return elem != xpathElem | |
} | |
var links = $("#parsely_site_body_wrapper a") | |
console.log(`%c ${links.length} links found`, mainTextStyles) | |
console.log("%c Searching...", elemStyles) | |
var invalidXpaths = links.filter(isNotOnlyInXpath).map((i, elem) => { | |
const xpath = ParselyOverlay.getElementXPath(elem) | |
const xpathTwin = ParselyOverlay.elemFromXPath(xpath) | |
return { | |
elem, | |
xpath, | |
xpathTwin, | |
} | |
}) | |
if (invalidXpaths.length) { | |
console.log(`%c ${invalidXpaths.length} invalid xpaths`, errorStyles) | |
console.groupCollapsed("xpath twins") | |
invalidXpaths.each((i, elem) => { | |
console.log(`%c ------`, dividerStyles) | |
console.log(`xpath:`) | |
console.log(`%c ${elem.xpath}`, xpathStyles) | |
console.log(`%c elem:`, elemStyles, elem.elem) | |
console.log(`%c xpathTwin:`, elemStyles, elem.xpathTwin) | |
}) | |
console.groupEnd() | |
console.log(invalidXpaths) | |
} else { | |
console.log("%c No duplicate xpaths - we all good!", mainTextStyles) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment