$x(\"//a[contains(@href,\'.jpg\')]\");
works as expected from the developer tools command prompt. But, when in an extension\'s content-script I get a \
I suggest adding this function to your code:
var xpath = function (xpathToExecute) {
var result = [];
var nodesSnapshot = document.evaluate(xpathToExecute, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < nodesSnapshot.snapshotLength; i++) {
result.push(nodesSnapshot.snapshotItem(i));
}
return result;
}
and Just calling it in place of $x