Search code examples
javascriptjquerytampermonkey

How to send Request only if string matches data


I would like my script to read the "ident" from the event data and if it matches a specific string. Print "hello" or something like that in console & if the "ident" doesn't matche the specific string. Send the post request.

Here is some of the data printed in a example. https://pastebin.com/ZMck0WsM

var evtSource = new EventSource("http://colorillo.com/_watch//_index?_=1559553617984");

evtSource.onmessage = function(e) {
var obj = JSON.parse(e.data);
var line = JSON.stringify(obj.line)

$.post("/draw.php?ing=_index", {
                l: (line),
                w: ("30"),
                c: ("#ffffff"),
                o: ("100"),
                f: ("1"),
                _: ("false")
            })
}

Solution

  • Try and if the following helps

    var match = ident.match(/[a-z]/); //remember to put the patten of what you want to match
    if(match){
      console.log(match)
    }else{
     //send post request
    }