This repository has been archived by the owner on Sep 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.js
70 lines (67 loc) · 1.9 KB
/
install.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
70
function installDefaults(){
/* Restructuring for v1.0
Defaults are now kept on local storage, and sync storage is only
used for user-created settings.
*/
var xhr = new XMLHttpRequest();
xhr.onload = function(){
var defaults = {
'version':chrome.app.getDetails().version
};
for(var i in xhr.response){
var j = xhr.response[i];
for(var k in j){
defaults[k] = j[k];
}
}
chrome.storage.local.set(defaults);
chrome.storage.sync.get('pageAction',function(items){
if(!items.hasOwnProperty('pageAction')){
chrome.storage.sync.set({'pageAction':true});
}
});
};
xhr.open("GET", chrome.extension.getURL('defaults.json')+"?"+(new Date()).getTime(), true);
xhr.responseType = "json";
xhr.send();
}
function wipeSettings(){
chrome.storage.sync.clear(function(){
installDefaults();
});
}
chrome.runtime.onInstalled.addListener(function(){
chrome.storage.sync.get('version',function(items){
if(items.version){
wipeSettings();
} else {
installDefaults();
}
});
});
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
if (message == "show_page_action") {
chrome.pageAction.show(sender.tab.id);
chrome.pageAction.setTitle(sender.tab.id, chrome.i18n.getMessage("extIconHover"));
} else if(message == "factoryReset"){
wipeSettings();
sendResponse("done");
} else if(message.notification){
function removeNotification(tabId, changes, tab){
chrome.notifications.clear("siteRule",function(yes){});
}
chrome.notifications.onButtonClicked.addListener(function(notification, button){
if(button==0){
chrome.storage.sync.set(message.details,function(){
location.reload();
});
} else {
removeNotification();
}
});
chrome.notifications.create("siteRule",message.notification, function(){
chrome.tabs.onUpdated.addListener(removeNotification);
chrome.tabs.onRemoved.addListener(removeNotification);
});
}
});