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

36 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-07-06 14:35:58 +02:00
document.addEventListener('DOMContentLoaded', function() {
2017-07-06 16:50:41 +02:00
var data = {request: {}};
function printData() {
document.querySelector('#response').innerHTML = JSON.stringify(data, null, 4);
}
2017-07-06 14:35:58 +02:00
(function createChannel() {
//Create a port with background page for continous message communication
2017-07-06 16:50:41 +02:00
var port = chrome.runtime.connect({
2017-07-06 14:35:58 +02:00
name: "Sample Communication" //Given a Name
});
// Listen to messages from the background page
port.onMessage.addListener(function(message) {
2017-07-06 16:50:41 +02:00
if (message.action === 'injectResponse') {
data.inject = message.data;
// port.postMessage(message);
2017-07-07 19:26:58 +02:00
} else if (message.action === "requestResponse" && message.file) {
2017-07-06 16:50:41 +02:00
data.request[message.file] = message.data;
}
printData()
2017-07-06 14:35:58 +02:00
});
}());
document.querySelector('#start').addEventListener('click', function() {
2017-07-07 19:26:58 +02:00
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);
2017-07-06 14:35:58 +02:00
console.log("sent message")
}, false);
});