forked from arikw/chrome-extensions-reloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
63 lines (59 loc) · 1.59 KB
/
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
function reloadExtensions()
{
// find all unpacked extensions and reload them
chrome.management.getAll(function(a) {
var ext = {};
for (var i = 0; i < a.length; i++) {
ext = a[i];
if ((ext.installType=="development") &&
(ext.enabled == true) &&
(ext.name != "Extensions Reloader")) {
console.log(ext.name + " reloaded");
(function (extensionId, extensionType) {
// disable
chrome.management.setEnabled(extensionId, false, function() {
// re-enable
chrome.management.setEnabled(extensionId, true, function() {
// re-launch packaged app
if (extensionType == "packaged_app") {
chrome.management.launchApp(extensionId);
}
});
});
})(ext.id, ext.type);
}
}
});
// show an "OK" badge
chrome.browserAction.setBadgeText({text: "OK"});
chrome.browserAction.setBadgeBackgroundColor({color: "#4cb749"});
setTimeout(function() {
chrome.browserAction.setBadgeText({text: ""});
}, 1000);
}
// intercept url
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if (details.url.indexOf("http://reload.extensions") >= 0) {
reloadExtensions();
chrome.tabs.get(details.tabId, function(tab) {
if (tab.selected == false) {
chrome.tabs.remove(details.tabId);
}
});
return {
// close the newly opened window
redirectUrl: chrome.extension.getURL("close.html")
};
}
return {cancel: false};
},
{
urls: ["http://reload.extensions/"],
types: ["main_frame"]
},
["blocking"]
);
chrome.browserAction.onClicked.addListener(function(tab) {
reloadExtensions();
});