javascriptxpathgreasemonkeydocument.evaluate

(document.evaluate) -> src of image contains multiple conditions, how?


please don't hit me with the hate stick. I'm a noob. hides in corner

I'm new to Greasemonkey and its syntax, so your help is much appreciated!

I'm trying to highlight several images based on words contained within their src url but I can't figure out the proper syntax for multiple conditions if the src isn't an entire match.

var snapImages =document.evaluate("//img[contains(@src, 'car']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);


for (var i = snapImages.snapshotLength - 1; i >= 0; i--) {
        var elmImage = snapImages.snapshotItem(i);

    elmImage.style.MozOutline = "5px solid red";
    }

This example works, but I need several more conditions. Like (@src, 'bike'), (@src, 'bus') etc. Again, I apologise for the newbish question. What is the proper syntax?

Thank you very much!

-Rocki


Solution

  • You can use and and or in XPath predicates, e.g.:

    //img[contains(@src, 'car') or contains(@src, 'bike')]
    

    Precedence is defined in the Booleans section of the spec.