amazonshubhamsdj / _Show word counts

// ==UserScript==
// @name     _Show word counts
// @version      0.2
// @include  https://genus.aka.amazon.com/*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @grant    GM_addStyle
// @downloadURL https://openuserjs.org/install/amazonshubhamsdj/_Show_word_counts.user.js
// @updateURL https://openuserjs.org/meta/amazonshubhamsdj/_Show_word_counts.meta.js
// @license MIT
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
    introduced in GM 1.0.   It restores the sandbox.
*/
$("body").append ('<div id="gmWordCount"></div>');

checkWordCount ();  //-- Initial run, works for static HTML only.

//--- Check for AJAX loaded words... Over twice a sec is plenty fast.
var wordChkTimer = setInterval (checkWordCount, 444);

function checkWordCount () {
    //--- Search for "of" as a whole word.
    var wordStr     = "Yes";
    var wordRegex   = new RegExp ("\\b" + wordStr + "\\b", "gi");
    var matchRez    = $(document.body).text ().match (wordRegex);
    var wordCount   = matchRez ? matchRez.length : 0;

    //--- Display the results.
    var countReport = '';
    switch (wordCount) {
        case 0:
            countReport = '"Yes" Available'
        break;
        case 1:
            countReport = ''
        break;
        default:
            countReport = '"Yes" was found ' + wordCount + ' times.'
        break;
    }

    //--- Display results to the user.
    $("#gmWordCount").text (countReport);
}

//--- Position and style the display output,
GM_addStyle ( "                                 \
    #gmWordCount {                              \
        background:         orange;             \
        position:           fixed;              \
        top:                0;                  \
        left:               0;                  \
        width:              100%;               \
        z-index:            6666;               \
    }                                           \
" );