Expanding chrome, parsing



  • It is necessary to write a simple extension for the site ' s password and, more specifically, to receive site status every 5 minutes. He's in.

    <span class="current_status">Онлайн</span>
    

    on site.com.

    When you press the expansion button, popup.js works for the ear.

    I can't write a background violin.js, for a sausage through a given time. This is the working code popup.js

    $(document).ready(function () {
    xhr = new XMLHttpRequest();
    xhr.open("GET", "http://site.com", true);
    xhr.send(null);
    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4) 
        {
            if (xhr.responseText) 
            {
                var data = xhr.responseText;
    
            var status = $('.current_status',data).html();
    
            chrome.browserAction.setIcon({
            path : "images/icon2.png"
            });
    
            $('#wrapper').html(status);
        }
    }
    

    }
    });

    Please indicate what to write in the background eventPage.js. It's the process of getting the data interesting. I sort of figured out the setInterval.
    Here's an inactive violin eventPage:

    xhr = new XMLHttpRequest();
    xhr.open("GET", "http://site.com", true);
    xhr.send(null);
    xhr.onreadystatechange = function() {
    if (xhr.readyState == 4)
    {
    if (xhr.responseText)
    {
    var data = xhr.responseText;

            status = getElementsByClassName('current_text')[0];
    
            alert(status);
    
    
        }
    }
    

    };



  • First, https://developer.mozilla.org/ru/docs/Web/API/Element/getElementsByClassName - It's not a global function, so you get a mistake with that challenge.

    The second, a browser can be used to deal with html and build DOM, for example, to create an element, to install an internal html, and to further seek an essential element inside.

    var element = document.createElement('div');
    element.innerHTML = data;
    

    var status = element.getElementsByClassName('current_text')[0];

    The variable is the element itself. In order to get the text, one of the properties is: https://developer.mozilla.org/ru/docs/Web/API/Element/innerHTML ♪ https://developer.mozilla.org/en-US/docs/Web/API/Node/innerText ♪ https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent

    console.log(status.innerHTML);
    console.log(status.innerText);
    console.log(status.textContent);




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2