Advertisement
Ladies_Man

rq_rsp XHR

Jul 25th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function request(url, tagname) {
  2.     var xhr = new XMLHttpRequest();
  3.    
  4.     xhr.open("GET", url, true);
  5.     xhr.onreadystatechange = function() {
  6.         if (xhr.readyState == 4 && xhr.status == 200) {
  7.                 if (xhr.responseText == null) console.log('null_rq');
  8.                 var doc = document.implementation.createHTMLDocument("tmp");
  9.                 doc.documentElement.innerHTML = xhr.responseText;
  10.                 console.log(doc.getElementById(tagname).innerText);
  11.             }
  12.         }
  13.     xhr.send();
  14.     return xhr.responseText;
  15. }
  16.  
  17. chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
  18.     console.log(sender.tab.url);
  19.     if (message.key == "info") {
  20.         console.log('Recideved "' + message.key + '" in background');
  21.        
  22.         var i, recieved_data = JSON.stringify(message.data);
  23.        
  24.         //alert('RECIEVED:' + recieved_data);
  25.         //save_result(recieved_data);
  26.         var curr_page;
  27.         var curr_url, mathnet_main_url = "http://mi.mathnet.ru/intf";
  28.         var url2 = "http://www.mathnet.ru/php/archive.phtml?wshow=paper&jrnid=intf&paperid=";
  29.         var url3 = "&option_lang=rus";
  30.         var tagname = "citPaperAMSBIBID";
  31.         for (i = 1; i < 5; i++) {
  32.             curr_url = url2 + i + url3;
  33.             curr_page = request(curr_url, tagname);
  34.             if (curr_page == null) console.log('null');
  35.             //alert(curr_page);
  36.         }
  37.        
  38.     }
  39.     if (message.key == "rq") {
  40.        
  41.     }
  42. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement