This repository was archived by the owner on Jul 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
76 lines (65 loc) · 2.15 KB
/
background.js
File metadata and controls
76 lines (65 loc) · 2.15 KB
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
(function (exported, MuteManager) {
"use strict";
var clients = [],
mute_manager = new MuteManager(localStorage.parseAndGetItem("muted"));
exported.getMutedAccounts = function () {
return mute_manager.muted.accounts;
};
exported.getMutedKeywords = function () {
return mute_manager.muted.keywords;
};
exported.add_account = function (account_name) {
var done = mute_manager.muteAccount(account_name);
if (done) {
update_clients();
}
return done;
};
exported.add_keyword = function (keyword) {
var done = mute_manager.muteKeyword(keyword);
if (done) {
update_clients();
}
return done;
};
exported.remove_account = function (account_name) {
var done = mute_manager.unMuteAccount(account_name);
if (done) {
update_clients();
}
return done;
};
exported.remove_keyword = function (keyword) {
var done = mute_manager.unMuteKeyword(keyword);
if (done) {
update_clients();
}
return done;
};
function update_clients() {
var i;
localStorage.stringifyAndSetItem("muted", mute_manager.muted);
for (i = clients.length - 1; i >= 0; i -=1) {
console.log("sending message to tab #" + clients[i]);
chrome.tabs.sendRequest(
clients[i],
{
type: "update",
data: {
backup: mute_manager.muted
}
},
null
);
}
}
chrome.extension.onRequest.addListener(
function (request, sender, sendResponse) {
console.log("received " + request.type + " request from tab #" + sender.tab.id);
if (clients.indexOf(sender.tab.id) === -1) {
clients.push(sender.tab.id);
}
sendResponse({type: "connection-response", data: {backup: mute_manager.muted}});
}
);
}(this, Twilter.MuteManager));