Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function request(url) {
- var xhr = new XMLHttpRequest();
- xhr.open("GET", url, true);
- xhr.onreadystatechange = function() {
- if (xhr.readyState == 4) {
- console.log(xhr.responseText);
- }
- }
- xhr.send();
- return JSON.parse(xhr.responseText);
- }
- function save_result(data) {
- chrome.tabs.create({
- active: false, url: 'http://www.editpad.org/'
- }, function(tab) {
- chrome.tabs.executeScript(tab.id, {
- code: 'document.getElementById("text").value = ' + data,
- }, function(result) {
- if (!result || null == result) {
- alert('Failed to run content script.\n' + chrome.runtime.lastError.message);
- return;
- }
- alert('SUBMITTED: "' + result[0] + '"');
- chrome.tabs.executeScript(tab.id, {
- code: 'document.getElementById("submitted").click()'
- });
- });
- }
- );
- }
- chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
- console.log(sender.tab.url);
- if (message.key == "info") {
- alert('Recideved "' + message.key + '" in background');
- var i, recieved_data = JSON.stringify(message.data);
- //alert('RECIEVED:' + recieved_data);
- save_result(recieved_data);
- var url = "http://www.mathnet.ru/php/contents.phtml?jrnid=intf&wshow=aindex&year=&volume=&option_lang=rus";
- var mathnet_main_page = request(url);
- chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
- chrome.tabs.sendMessage(tabs[0].id, {
- key: "mathnet",
- data: mathnet_main_page,
- tagname: "SLink"
- }, function(response) {});
- });
- }
- if (message.key == "rq") {
- }
- });
- var text_to_send;
- function access_page_stuff(name) {
- var i, tmp, results;
- results = document.getElementsByClassName(name);
- alert('num of "' + name + '":' + results.length);
- text_to_send = '';
- for (i = 0; i < results.length; i++) {
- text_to_send += results[i].innerText;
- }
- //alert('SENT(' + results.length + '): ' + text_to_send);
- chrome.runtime.sendMessage({key: "info", data: text_to_send}, function(response){});
- }
- function test_connection(tagname, data, curr_i, max_i, stop) {
- if (max_i == curr_i) {
- alert('STOP:' + curr_i);
- return;
- }
- curr_i++;
- chrome.runtime.sendMessage({
- }, function(response) {});
- }
- chrome.extension.onMessage.addListener(function(msg, sender, sendResponse) {
- switch (msg.key) {
- case "start":
- access_page_stuff(msg.tagname);
- break;
- case "mathnet":
- alert(msg.data);
- break;
- case "test_back":
- test_connection(msg.tagname, msg.data, msg.curr_i, msg.max_i, msg.stop);
- break;
- }
- });
- /*
- chrome.runtime.onMessage.addListener( function(msg, sender, sendResponse) {
- switch (msg.key) {
- case "start":
- alert('recieved msg 2');
- get_stuff_from_page(msg.text);
- }
- });*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement