-
Notifications
You must be signed in to change notification settings - Fork 0
/
righelli-background.js
69 lines (58 loc) · 2.5 KB
/
righelli-background.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
This file is part of Righelli.
Righelli is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Righelli is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Righelli. If not, see <http://www.gnu.org/licenses/>.
*/
var righelliBackground = {};
righelliBackground.connectListener = function (port) {
if (port.name == "devtools-righelli") {
port.onDisconnect.addListener(righelliBackground.disconnectListener);
}
};
righelliBackground.disconnectListener = function(port) {
righelliBackground.sendCmdToContentScript("exit");
};
righelliBackground.loadRighelli = function(iTabId) {
righelliBackground.sendCmdToContentScript("init", function (response) {
if (!response) { //the script hasn't been previously loaded, let's do it now
chrome.tabs.insertCSS(iTabId, {file: "righelli.css"});
chrome.tabs.executeScript(iTabId, {file: "jquery.min.js"});
chrome.tabs.executeScript(iTabId, {file: "righelli.js" });
}
});
};
righelliBackground.messageListener = function(message,sender,sendResponse){
if (message.cmd == "init") {
if (message.cmd == "init" && message.opt == "ignore_settings") {
righelliBackground.loadRighelli(message.tabId);
} else {
chrome.storage.sync.get({
showAtStartup: false
}, function(oSettings) {
if (oSettings.showAtStartup) {
righelliBackground.loadRighelli(message.tabId);
}
});
}
}
};
righelliBackground.sendMessageToContentScript = function (oMsg, fnCallback) {
chrome.tabs.query({active: true, currentWindow: true},
function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, oMsg, fnCallback);
});
};
righelliBackground.sendCmdToContentScript = function (sCmd, fnCallback) {
righelliBackground.sendMessageToContentScript({cmd: sCmd}, fnCallback);
};
//Setup listeners
chrome.runtime.onConnect.addListener(righelliBackground.connectListener);
chrome.runtime.onMessage.addListener(righelliBackground.messageListener);