-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
82 lines (77 loc) · 2.73 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// This is the background page.
// it keeps track of prefrences/settings in localStorage
if (typeof chrome !== "undefined") {
var browser = chrome;
}
browser.runtime.onMessage.addListener(function (messageEvent, sender, callback)
{
if (messageEvent.name == "setOptions")
{
if ("presenceUpdatesHook" in messageEvent)
{
chrome.storage.local.set({"presenceUpdatesHook": messageEvent.presenceUpdatesHook});
}
if ("readConfirmationsHook" in messageEvent)
{
chrome.storage.local.set({"readConfirmationsHook": messageEvent.readConfirmationsHook});
}
if ("safetyDelay" in messageEvent)
{
chrome.storage.local.set({"safetyDelay": messageEvent.safetyDelay});
}
if ("showReadWarning" in messageEvent)
{
chrome.storage.local.set({"showReadWarning": messageEvent.showReadWarning});
}
if ("saveDeletedMsgs" in messageEvent)
{
chrome.storage.local.set({"saveDeletedMsgs": messageEvent.saveDeletedMsgs});
}
}
else if (messageEvent.name == "getOptions")
{
// these are the default values. we will update them according to the storage
var presenceUpdatesHook = true;
var readConfirmationsHook = true;
var showReadWarning = true;
var safetyDelay = 0;
var saveDeletedMsgs = false;
chrome.storage.local.get(['presenceUpdatesHook', 'readConfirmationsHook', 'showReadWarning', 'safetyDelay', 'saveDeletedMsgs']).then(function(storage)
{
if (storage["presenceUpdatesHook"] != undefined)
{
presenceUpdatesHook = storage["presenceUpdatesHook"];
}
if (storage["readConfirmationsHook"] != undefined)
{
readConfirmationsHook = storage["readConfirmationsHook"];
}
if (storage["showReadWarning"] != undefined)
{
showReadWarning = storage["showReadWarning"];
}
if (storage["safetyDelay"] != undefined)
{
safetyDelay = storage["safetyDelay"];
}
if (storage["saveDeletedMsgs"] != undefined)
{
saveDeletedMsgs = storage["saveDeletedMsgs"];
}
callback(
{
presenceUpdatesHook: presenceUpdatesHook,
readConfirmationsHook: readConfirmationsHook,
showReadWarning: showReadWarning,
safetyDelay: safetyDelay,
saveDeletedMsgs: saveDeletedMsgs
});
});
}
return true;
});
browser.action.onClicked.addListener(function(activeTab)
{
var newURL = "https://web.whatsapp.com";
browser.tabs.create({ url: newURL });
});