0

this comes from google chrome extension codes

"search" == request.ajax && $.ajax({
        url: request.url,
        type: "GET",
        dataType: "html"
      }).done(function(msg) {
        if (msg.indexOf("https://login.testabc.com/?from=sm&return_url=") > -1)
          return void chrome.tabs.query({
            index: tabs[0].index
          }, function(a) {
            chrome.tabs.sendMessage(a[0].id, {
              type: "ezusy_searched",
              dataSearch: "login"
            }, function(a) {})
          });
        var data = jQuery(msg), script; //what is msg && script?
        data.each(function(a) {
          $(this).text().indexOf("window.runParams") > -1 && (script = $(this).text())
        }),
          eval(script); //what does it mean?

what are the script and msg? why code like this.

zach
  • 1
  • 1

2 Answers2

0

We would need to see a bit larger context to know the overall purpose of this code, but in general, this code is fetching some content from the page and if it finds "window.runParams" in that content, then it's assigning that content into the script variable with script = $(this).text() and then executing it as Javascript with eval(script).

jfriend00
  • 683,504
  • 96
  • 985
  • 979
0

You can check out the link I have attached for more detail. I will extract some of the content here:

(i) $.ajax().done()

$.ajax() returns an jqXHR object.

Then according to the specification - jqXHR.done(function( data, textStatus, jqXHR ) {});, the msg variable in your code snippet refer to the data parameter.

Reference: https://api.jquery.com/jquery.ajax#jqXHR

(ii) JavaScript variable definition: Commas vs. Semicolons

The script variable is just a variable that you declared in your code

(iii) eval()

The eval() function evaluates JavaScript code represented as a string.

Reference: https://developer.mozilla.org/enUS/docs/Web/JavaScript/Reference/Global_Objects/eval

jackycflau
  • 1,101
  • 1
  • 13
  • 33