-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.html
100 lines (88 loc) · 2.38 KB
/
background.html
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
<!DOCTYPE html>
<html>
<head>
<script src="jquery.min.js"></script>
<script src="json2.js"></script>
<script>
/**
*
* @author : [email protected]
* @license : GPLv3
*/
var S_MUTED_TOPICS = 'muted_topics',
//S_BLOCKED_USERS = 'blocked_users',
S_ONLY_LOCAL_MEMBERS = 'is_only_local_mermbers',
S_ONLY_NEW_MEMBERS = 'is_only_new_mermbers';
function _str2ar(str){
var result = [];
('string' === typeof str) && $.each(str.split(','), function(idx, el)
{
if(el.length > 0)
{
result.push(el);
}
});
return result;
}
var muted_topics = _str2ar(localStorage[S_MUTED_TOPICS]);
/* legacy competity, will remove in future */
$.each(_str2ar(localStorage['mutedTopics']), function(idx, el){
muted_topics.push(el);
});
chrome.extension.onRequest.addListener(function(request, sender, sendResponse)
{
if(request.action)
{
switch(request.action)
{
case 'showPgAct':
chrome.pageAction.show(sender.tab.id);
sendResponse();
break;
case 'muteTopic':
if(request.objectId)
{
sendResponse({"done":1});
if(-1 === $.inArray(request.objectId, muted_topics))
{
muted_topics.push(request.objectId);
localStorage[S_MUTED_TOPICS] = muted_topics;
}
}
else
{
sendResponse({"done":0});
}
break;
case 'load_storage':
sendResponse({
"done" : 1,
"muted_topic": muted_topics,
'show_only_local_members': localStorage[S_MUTED_TOPICS],
'show_only_new_members': localStorage[S_ONLY_NEW_MEMBERS]
});
break;
case 'clearData':
localStorage[S_MUTED_TOPICS] = muted_topics = [];
sendResponse({"done": 1});
break;
case 'load_data':
sendResponse({
'done': 1,
'data': JSON.parse(localStorage[request.key] || '{}')
});
break;
case 'save_data':
localStorage[request.key] = JSON.stringify(request.value);
sendResponse({"done": 1});
break;
}
}
else
{
sendResponse({"done": 0});
}
});
</script>
</head>
</html>