How to use if to find a substring inside a string with JavaScript or jQuery, using TamperMonkey and possibly an array? -


so i'm writing tampermonkey script use on facebook (as might tell on id's & classes) , i've run wall. total writers block. i'm trying figure out how can write if statement allow me find specific strings in existing string. now, i've looked around ideas , regular expressions aren't working me, nor .test or .match working me either. i'm little confused , needing insight might able do. love use array if possible since i'm going searching many strings.

here snippet of code need help:

var checkname = setinterval(function() {     if ($("span[id^='fb-timeline-cover-name']").length) {         var str = document.getelementbyid("fb-timeline-cover-name").innertext;         var res = str.tolowercase();         if (res.substring(0,3) == "ssg") {             $("button[id^='u_0_12']").click();         }         clearinterval(checkname);     } }, 50); 

instead of:

if(res.substring(0,3) == "ssg") { 

i'd able simple like:

if(res.match(this_array)) { 

but i'm sure that's wrong syntax together. anyone? help? in advance!

it seems string/match can useful.

but not sure this_array referring here.

hope snippet useful

var str = document.getelementbyid("fb-timeline-cover-name").innertext; var res = str.match(/asdfssgasdf/g); document.write('<pre>'+res+'</pre>'); 

jsfiddle

edit

another string method can handy string includes.

it retuns boolean value, true or false


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -