1
0
Fork 0
This repository has been archived on 2024-06-28. You can view files and clone it, but cannot push or open issues or pull requests.
piwik-checker/js/panel.js
2017-07-08 13:03:13 +02:00

35 lines
1.3 KiB
JavaScript

document.addEventListener('DOMContentLoaded', function() {
var data = {request: {}};
function printData() {
document.querySelector('#response').innerHTML = JSON.stringify(data, null, 4);
}
(function createChannel() {
//Create a port with background page for continous message communication
var port = chrome.runtime.connect({
name: "Sample Communication" //Given a Name
});
// Listen to messages from the background page
port.onMessage.addListener(function(message) {
if (message.action === 'injectResponse') {
data.inject = message.data;
// port.postMessage(message);
} else if (message.action === "requestResponse" && message.file) {
data.request[message.file] = message.data;
}
printData()
});
}());
document.querySelector('#start').addEventListener('click', function() {
chrome.runtime.sendMessage({action: "inject", tabId: chrome.devtools.inspectedWindow.tabId});
chrome.runtime.sendMessage({action: "request", tabId: chrome.devtools.inspectedWindow.tabId});
// chrome.tabs.reload(chrome.devtools.inspectedWindow.tabId);
console.log("sent message")
}, false);
});