0

I thought I would share with the community my somewhat unique spin on targeting elements that contain keywords of text, yet ignoring capital letters, then finishing off with a little CSS to the element. I don't every proclaim my code I use is ever perfect, but please if you see improving, feel free, enjoy.

computerguy
  • 177
  • 9
  • This is not how you share knowledge at Stack Overflow. (But you might be able to tweak the answer for [Documentation](http://stackoverflow.com/documentation/), maybe.) .. A self answered question still needs to be a real question, per the [faq], and not a duplicate or a generic, "I want to share some code". ... Kudos for wanting to give back, but this is not quite the way to do it here. – Brock Adams Aug 18 '16 at 04:05
  • ok thank you very much :) – computerguy Aug 18 '16 at 04:34

1 Answers1

0

Here is the following code:

This section basically says to ignore capitals:

jQuery.expr[':'].contains = function(a, i, m) {
  return jQuery(a).text().toUpperCase()
      .indexOf(m[3].toUpperCase()) >= 0;
};

This section basically selects the element based on keywords, and also applies some CSS:

var array1 = ['trump', 'blah', 'hillary', 'blah'];
$(array1).each(function () {
    $(".yt-shelf-grid-item:contains(" + this + ")").css({"opacity":"1","filter":"grayscale(100%) brightness(30%) contrast(77%)"});
});

Try not to touch this:

function addJQuery(callback) {
    var script = document.createElement("script");
    script.setAttribute("src", "https://code.jquery.com/jquery-2.0.3.min.js");
    script.addEventListener('load', function() {
        var script = document.createElement("script");
        script.textContent = "window.jQQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
        document.body.appendChild(script);
    }, false);
    document.body.appendChild(script);
}
computerguy
  • 177
  • 9
  • 1
    What does the "try not to touch this" part have to do with anything? (I see what it *does*, just not why it is relevant to the subject at hand.) – nnnnnn Aug 18 '16 at 03:35
  • not really necessary to modify versus the previous sections – computerguy Aug 18 '16 at 03:45
  • 2
    I mean, why do you even show that code in the answer at all? It has nothing to do with the subject of the question, and it isn't used by the other code in the answer. – nnnnnn Aug 18 '16 at 03:46