forked from tomer8007/whatsapp-web-incognito
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
138 lines (133 loc) · 4.96 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// This is the background page.
// it keeps track of prefrences/settings in localStorage
if (typeof chrome !== "undefined") {
var browser = chrome;
}
// TODO: We need to remove this bad code dupliation
browser.runtime.onMessage.addListener(function (messageEvent, sender, callback)
{
if (messageEvent.name == "setOptions")
{
if ("onlineUpdatesHook" in messageEvent)
{
chrome.storage.local.set({"onlineUpdatesHook": messageEvent.onlineUpdatesHook});
}
if ("typingUpdatesHook" in messageEvent)
{
chrome.storage.local.set({"typingUpdatesHook": messageEvent.typingUpdatesHook});
}
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});
}
if ("showDeviceTypes" in messageEvent)
{
chrome.storage.local.set({"showDeviceTypes": messageEvent.showDeviceTypes});
}
if ("autoReceiptOnReplay" in messageEvent)
{
chrome.storage.local.set({"autoReceiptOnReplay": messageEvent.autoReceiptOnReplay});
}
if ("allowStatusDownload" in messageEvent)
{
chrome.storage.local.set({"allowStatusDownload": messageEvent.allowStatusDownload});
}
}
else if (messageEvent.name == "getOptions")
{
// these are the default values. we will update them according to the storage
var onlineUpdatesHook = false;
var typingUpdatesHook = false;
var notifytyping = false;
var readConfirmationsHook = true;
var showReadWarning = true;
var safetyDelay = 0;
var saveDeletedMsgs = false;
var showDeviceTypes = true;
var autoReceiptOnReplay = true;
var allowStatusDownload = true;
chrome.storage.local.get(['onlineUpdatesHook',
'typingUpdatesHook',
'notifytyping',
'readConfirmationsHook',
'showReadWarning',
'safetyDelay',
'saveDeletedMsgs',
'showDeviceTypes',
'autoReceiptOnReplay',
'allowStatusDownload']).then(function(storage)
{
if (storage["onlineUpdatesHook"] != undefined)
{
onlineUpdatesHook = storage["onlineUpdatesHook"];
}
if (storage["typingUpdatesHook"] != undefined)
{
typingUpdatesHook = storage["typingUpdatesHook"];
}
if (storage["notifytyping"] != undefined)
{
notifytyping = storage["notifytyping"];
}
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"];
}
if (storage["showDeviceTypes"] != undefined)
{
showDeviceTypes = storage["showDeviceTypes"];
}
if (storage["autoReceiptOnReplay"] != undefined)
{
autoReceiptOnReplay = storage["autoReceiptOnReplay"];
}
if (storage["allowStatusDownload"] != undefined)
{
allowStatusDownload = storage["allowStatusDownload"];
}
callback(
{
onlineUpdatesHook: onlineUpdatesHook,
typingUpdatesHook: typingUpdatesHook,
notifytyping: notifytyping,
readConfirmationsHook: readConfirmationsHook,
showReadWarning: showReadWarning,
safetyDelay: safetyDelay,
saveDeletedMsgs: saveDeletedMsgs,
showDeviceTypes: showDeviceTypes,
autoReceiptOnReplay: autoReceiptOnReplay,
allowStatusDownload: allowStatusDownload
});
});
}
return true;
});
browser.action.onClicked.addListener(function(activeTab)
{
var newURL = "https://web.whatsapp.com";
browser.tabs.create({ url: newURL });
});