-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbackground.js
More file actions
executable file
·67 lines (55 loc) · 1.93 KB
/
background.js
File metadata and controls
executable file
·67 lines (55 loc) · 1.93 KB
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
var EXTENSION_ID = "le-git-imate";
var SCRIPTS = ["./libs/jquery.min.js", "./libs/openpgp.js", "./libs/sha1.js", "./libs/bundle.js",
"./commit/createObject.js", "./commit/createPackfile.js", "app.js", "dispatch.js",
"./config/setup.js", "./connection/request.js"];
function injectScripts(files, after) {
var _this = this;
_this.files = files;
_this.js = [];
_this.head = document.getElementsByTagName("head")[0];
_this.after = after || function() {};
// Add scripts to the page
_this.loadScript = function(i) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = _this.js[i];
var loadNextScript = function() {
if (++i < _this.js.length)
_this.loadScript(i);
else
_this.after();
};
script.onload = function() {
loadNextScript()
};
_this.head.appendChild(script);
}
for (var i = 0; i < _this.files.length; i++) {
if (/\.js$|\.js\?/.test(_this.files[i]))
_this.js.push(_this.files[i])
}
if (_this.js.length > 0)
_this.loadScript(0);
else
_this.after();
}
// TODO: Use options to handle popup window
function setPopupWindow() {
retrieveObject(EXTENSION_ID).then((privArmored) => {
if (privArmored === undefined) { // setup if key is not found
chrome.browserAction.setPopup({
popup: 'popup.html'
});
//reload the page after key settings
window.location.reload(true);
window.location.href = "chrome://extensions/"
window.location.reload(true);
} else { // perform the user request if key is found
chrome.browserAction.setPopup({
popup: 'app.html'
});
}
});
}
// Inject local scripts, and then set the popup window
injectScripts(SCRIPTS, setPopupWindow);