This repository has been archived by the owner on Apr 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
background.js
58 lines (52 loc) · 1.91 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
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-35892158-1']);
_gaq.push(['_gat._anonymizeIp']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})()
var settings = new Store('settings', {
'block_chat_seen': true,
'block_typing_indicator': false,
'hide_chat_seen': false,
'show_mark_as_read': true
// TODO
// 'block_group_seen': false
})
if (!settings.get('block_chat_seen')) {
chrome.browserAction.setIcon({path: 'icon48.disabled.png'})
}
chrome.webRequest.onBeforeRequest.addListener(function(details) {
return {
cancel: settings.get('block_chat_seen')
}
}, { urls: ['*://*.facebook.com/*change_read_status*'] }, ['blocking'])
chrome.webRequest.onBeforeRequest.addListener(function(details) {
return {
cancel: settings.get('block_typing_indicator')
}
}, { urls: ['*://*.facebook.com/*typ.php*'] }, ['blocking'])
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.action == 'getSettings') {
sendResponse(settings.toObject())
}
else if (request.action == 'getDisableButton') {
sendResponse(localStorage['force_disable_button'])
}
else if (request.action == 'setDisableButton') {
localStorage['force_disable_button'] = 'true'
chrome.tabs.create({url: 'http://swege.github.io/fb-unseen/', active: false})
_gaq.push(['_trackEvent', 'Mark as read', 'forceDisable'])
}
else if (request.action == 'quickDisable') {
chrome.browserAction.setIcon({path: 'icon48.disabled.png'})
}
else if (request.action == 'quickEnable') {
chrome.browserAction.setIcon({path: 'icon48.png'})
}
else if (request.action == 'trackMarkAsRead') {
_gaq.push(['_trackEvent', 'MarkAsRead', 'clicked']);
}
})