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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
/*
* This file is part of Adblock Plus <https://adblockplus.org/>,
* Copyright (C) 2006-2015 Eyeo GmbH
*
* Adblock Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* Adblock Plus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
(function()
{
function E(id)
{
return document.getElementById(id);
}
// Load subscriptions for features
var featureSubscriptions = [
{
feature: "malware",
homepage: "http://malwaredomains.com/",
title: "Malware Domains",
url: "https://easylist-downloads.adblockplus.org/malwaredomains_full.txt"
},
{
feature: "social",
homepage: "https://www.fanboy.co.nz/",
title: "Fanboy's Social Blocking List",
url: "https://easylist-downloads.adblockplus.org/fanboy-social.txt"
},
{
feature: "tracking",
homepage: "https://easylist.adblockplus.org/",
title: "EasyPrivacy",
url: "https://easylist-downloads.adblockplus.org/easyprivacy.txt"
}
];
function getDocLink(link, callback)
{
ext.backgroundPage.sendMessage({
type: "app.get",
what: "doclink",
link: link
}, callback);
}
function onDOMLoaded()
{
// Set up logo image
var logo = E("logo");
logo.src = "skin/abp-128.png";
var errorCallback = function()
{
logo.removeEventListener("error", errorCallback, false);
// We are probably in Chrome/Opera/Safari, the image has a different path.
logo.src = "icons/detailed/abp-128.png";
};
logo.addEventListener("error", errorCallback, false);
// Set up URLs
getDocLink("donate", function(link)
{
E("donate").href = link;
});
getDocLink("contributors", function(link)
{
E("contributors").href = link;
});
getDocLink("acceptable_ads_criteria", function(link)
{
setLinks("acceptableAdsExplanation", link, openFilters);
});
getDocLink("contribute", function(link)
{
setLinks("share-headline", link);
});
ext.backgroundPage.sendMessage({
type: "app.get",
what: "issues"
}, function(issues)
{
// Show warning if data corruption was detected
if (issues.seenDataCorruption)
{
E("dataCorruptionWarning").removeAttribute("hidden");
getDocLink("knownIssuesChrome_filterstorage", function(link)
{
setLinks("dataCorruptionWarning", link);
});
}
// Show warning if filterlists settings were reinitialized
if (issues.filterlistsReinitialized)
{
E("filterlistsReinitializedWarning").removeAttribute("hidden");
setLinks("filterlistsReinitializedWarning", openFilters);
}
if (issues.legacySafariVersion)
E("legacySafariWarning").removeAttribute("hidden");
});
// Set up feature buttons linked to subscriptions
featureSubscriptions.forEach(initToggleSubscriptionButton);
updateToggleButtons();
updateSocialLinks();
ext.onMessage.addListener(function(message)
{
if (message.type == "subscriptions.listen")
{
updateToggleButtons();
updateSocialLinks();
}
});
ext.backgroundPage.sendMessage({
type: "subscriptions.listen",
filter: ["added", "removed", "updated", "disabled"]
});
}
function initToggleSubscriptionButton(featureSubscription)
{
var feature = featureSubscription.feature;
var element = E("toggle-" + feature);
element.addEventListener("click", function(event)
{
ext.backgroundPage.sendMessage({
type: "subscriptions.toggle",
url: featureSubscription.url,
title: featureSubscription.title,
homepage: featureSubscription.homepage
});
}, false);
}
function openSharePopup(url)
{
var iframe = E("share-popup");
var glassPane = E("glass-pane");
var popupMessageReceived = false;
var popupMessageListener = function(event)
{
if (!/[.\/]adblockplus\.org$/.test(event.origin))
return;
var width = event.data.width;
var height = event.data.height;
iframe.width = width;
iframe.height = height;
iframe.style.marginTop = -height/2 + "px";
iframe.style.marginLeft = -width/2 + "px";
popupMessageReceived = true;
window.removeEventListener("message", popupMessageListener);
};
// Firefox requires last parameter to be true to be triggered by unprivileged pages
window.addEventListener("message", popupMessageListener, false, true);
var popupLoadListener = function()
{
if (popupMessageReceived)
{
iframe.className = "visible";
var popupCloseListener = function()
{
iframe.className = glassPane.className = "";
document.removeEventListener("click", popupCloseListener);
};
document.addEventListener("click", popupCloseListener, false);
}
else
{
glassPane.className = "";
window.removeEventListener("message", popupMessageListener);
}
iframe.removeEventListener("load", popupLoadListener);
};
iframe.addEventListener("load", popupLoadListener, false);
iframe.src = url;
glassPane.className = "visible";
}
function updateSocialLinks()
{
var networks = ["twitter", "facebook", "gplus"];
networks.forEach(function(network)
{
var link = E("share-" + network);
var message = {
type: "filters.blocked",
url: link.getAttribute("data-script"),
requestType: "SCRIPT",
docDomain: "adblockplus.org",
thirdParty: true
};
ext.backgroundPage.sendMessage(message, function(blocked)
{
// Don't open the share page if the sharing script would be blocked
if (blocked)
link.removeEventListener("click", onSocialLinkClick, false);
else
link.addEventListener("click", onSocialLinkClick, false);
});
});
}
function onSocialLinkClick(event)
{
event.preventDefault();
getDocLink(event.target.id, function(link)
{
openSharePopup(link);
});
}
function setLinks(id)
{
var element = E(id);
if (!element)
{
return;
}
var links = element.getElementsByTagName("a");
for (var i = 0; i < links.length; i++)
{
if (typeof arguments[i + 1] == "string")
{
links[i].href = arguments[i + 1];
links[i].setAttribute("target", "_blank");
}
else if (typeof arguments[i + 1] == "function")
{
links[i].href = "javascript:void(0);";
links[i].addEventListener("click", arguments[i + 1], false);
}
}
}
function openFilters()
{
ext.backgroundPage.sendMessage({type: "app.open", what: "options"});
}
function updateToggleButtons()
{
ext.backgroundPage.sendMessage({
type: "subscriptions.get",
downloadable: true,
ignoreDisabled: true
}, function(subscriptions)
{
var known = Object.create(null);
for (var i = 0; i < subscriptions.length; i++)
known[subscriptions[i].url] = true;
for (var i = 0; i < featureSubscriptions.length; i++)
{
var featureSubscription = featureSubscriptions[i];
updateToggleButton(featureSubscription.feature, featureSubscription.url in known);
}
});
}
function updateToggleButton(feature, isEnabled)
{
var button = E("toggle-" + feature);
if (isEnabled)
button.classList.remove("off");
else
button.classList.add("off");
}
document.addEventListener("DOMContentLoaded", onDOMLoaded, false);
})();
|