javascriptjqueryfilterprofanity

jQuery.ProfanityFilter count


I am using jQuery.ProfanityFilter to find swear words in a page. The code is below:

$divs.profanityFilter({
            customSwears: ['drunk'],
            externalSwears: 'swearWords.json',
            filter: false,
            profaneText: function (data) {

                alert("swear!");
            }
        });

My question is would there be any way of counting the amount of swear words that are found? I cannot seem to find a suitable way of adapting the code.

Any help would be greatly appreciated.


Solution

  • You may be able to modify your plugin slightly. Based on the link presented by @DontVoteMeDown, you may be able to manually change the profaneText function in the plugin file directly to work with your implementation of it.

    In the Plugin File

    if (profane) {
      options.profaneText(data.unique(), data.length);
    };
    

    Then in your own JQuery implementation of the plugin:

    $divs.profanityFilter({
            customSwears: ['drunk'],
            externalSwears: 'swearWords.json',
            filter: false,
            profaneText: function (data, size) {
              console.log("Swear words in element: " + data);
              console.log("Number of swear words: " + size);
            }
        });