forked from ocodia/Hide-Twitter-Guff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
71 lines (62 loc) · 1.64 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
var logging = false;
//sets the item in the localstorage
function setItem(key, value) {
try {
log("Inside setItem:" + key + ":" + value);
window.localStorage.removeItem(key);
window.localStorage.setItem(key, value);
}catch(e) {
log("Error inside setItem");
log(e);
}
log("Return from setItem" + key + ":" + value);
}
//Gets the item from local storage with the specified
//key
function getItem(key) {
var value;
log('Get Item:' + key);
try {
value = window.localStorage.getItem(key);
}catch(e) {
log("Error inside getItem() for key:" + key);
log(e);
value = "null";
}
log("Returning value: " + value);
return value;
}
//Clears all the key value pairs in the local storage
function clearStrg() {
log('about to clear local storage');
window.localStorage.clear();
log('cleared');
}
function log(txt) {
if(logging) {
console.log(txt);
}
}
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse)
{
chrome.pageAction.show(sender.tab.id);
switch (request.name)
{
case "getPreferences":
// request from the content script to get the preferences.
sendResponse(
{
WTF : localStorage["showWTF"],
TRENDS : localStorage["showTRENDS"]
});
break;
default:
sendResponse({});
}
}
);
chrome.pageAction.onClicked.addListener(function(tab) {
var url = chrome.extension.getURL('options.html');
chrome.tabs.create({selected:true, url:url});
});