-
Notifications
You must be signed in to change notification settings - Fork 0
/
tab_communication.js
41 lines (35 loc) · 1.17 KB
/
tab_communication.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function tabReceivedMessage(message) {
switch (message.title) {
case message_titles.REQUEST:
return processRequest(message.content.sendable_data_title, message.content);
case message_titles.EXECUTE_SCRIPT:
return executeScript(message.content);
}
}
function sendMessageToPopup(title, content={}) {
chrome.runtime.sendMessage({
title: title,
content: content,
recipient: recipients.POPUP
});
}
function sendResponseDataToPopup(sendable_data_title, data) {
sendMessageToPopup(message_titles.RESPONSE, {
sendable_data_title: sendable_data_title,
data: data,
})
}
function sendUrlToPopup() {
sendResponseDataToPopup(message_titles.sendable_data.URL, getCurrentTabUrl())
}
function sendActiveScriptsToPopup() {
sendResponseDataToPopup(message_titles.sendable_data.ACTIVE_SCRIPTS, getActiveScripts())
}
function processRequest(sendable_data_title, content) {
switch (sendable_data_title) {
case message_titles.sendable_data.URL:
return sendUrlToPopup();
case message_titles.sendable_data.ACTIVE_SCRIPTS:
return sendActiveScriptsToPopup();
}
}