Q:

JavaScript count all elements on a webpage

I want to be able to count everything on a site that contains a certain string, even if it's not displayed on the page.
I found this:
window.occurrencesFunc()

I am not sure how to use it. I did play around with it, but nothing seemed to work.
This is what I tried:
function main() {
    function(r) {
        var amount = window.occurrencesFunc(r, "string", false);
        $('ul.reset').append('Count: ' + amount);
    }
}

main();

A:

I'd get the entire page as a string:
var markup = document.documentElement.innerHTML;

And, then I'd use the match method to match for the string occurrences in the string and count them:
// the g in the regular expression says to search for a word (not part of a word)
var resultArray= markup.match(/WORRDDD/g);

var count = resultArray.length

Shorthand, would be 
var count = (markup.match(/WORRDDD/g) || []).length;

