OLD | NEW |
1 var backgroundPage = opera.extension.bgProcess; | 1 var backgroundPage = opera.extension.bgProcess; |
2 var imports = ["FilterStorage", "FilterNotifier", "Subscription", "SpecialSubscr
iption", | 2 var require = backgroundPage.require; |
3 "DownloadableSubscription", "Filter", "WhitelistFilter", | 3 |
4 "Synchronizer", "Prefs", "Utils", "require"]; | 4 with(require("filterClasses")) |
5 for (var i = 0; i < imports.length; i++) | 5 { |
6 window[imports[i]] = backgroundPage[imports[i]]; | 6 this.Filter = Filter; |
| 7 this.WhitelistFilter = WhitelistFilter; |
| 8 } |
| 9 with(require("subscriptionClasses")) |
| 10 { |
| 11 this.Subscription = Subscription; |
| 12 this.SpecialSubscription = SpecialSubscription; |
| 13 this.DownloadableSubscription = DownloadableSubscription; |
| 14 } |
| 15 var FilterStorage = require("filterStorage").FilterStorage; |
| 16 var FilterNotifier = require("filterNotifier").FilterNotifier; |
| 17 var Prefs = require("prefs").Prefs; |
| 18 var Synchronizer = require("synchronizer").Synchronizer; |
7 | 19 |
8 // Loads options from localStorage and sets UI elements accordingly | 20 // Loads options from localStorage and sets UI elements accordingly |
9 function loadOptions() | 21 function loadOptions() |
10 { | 22 { |
11 // Set page title to i18n version of "Adblock Plus Options" | 23 // Set page title to i18n version of "Adblock Plus Options" |
12 document.title = i18n.getMessage("options"); | 24 document.title = i18n.getMessage("options"); |
13 | 25 |
14 // Set links | 26 // Set links |
15 $("#acceptableAdsLink").attr("href", Prefs.subscriptions_exceptionsurl); | 27 $("#acceptableAdsLink").attr("href", Prefs.subscriptions_exceptionsurl); |
16 $("#acceptableAdsDocs").attr("href", Prefs.documentation_link.replace(/%LINK%/
g, "acceptable_ads").replace(/%LANG%/g, Utils.appLocale)); | 28 $("#acceptableAdsDocs").attr("href", Prefs.documentation_link.replace(/%LINK%/
g, "acceptable_ads").replace(/%LANG%/g, require("utils").Utils.appLocale)); |
17 | 29 |
18 // Add event listeners | 30 // Add event listeners |
19 window.addEventListener("unload", unloadOptions, false); | 31 window.addEventListener("unload", unloadOptions, false); |
20 $("#updateFilterLists").click(updateFilterLists); | 32 $("#updateFilterLists").click(updateFilterLists); |
21 $("#startSubscriptionSelection").click(startSubscriptionSelection); | 33 $("#startSubscriptionSelection").click(startSubscriptionSelection); |
22 $("#subscriptionSelector").change(updateSubscriptionSelection); | 34 $("#subscriptionSelector").change(updateSubscriptionSelection); |
23 $("#addSubscription").click(addSubscription); | 35 $("#addSubscription").click(addSubscription); |
24 $("#acceptableAds").click(allowAcceptableAds); | 36 $("#acceptableAds").click(allowAcceptableAds); |
25 $("#whitelistForm").submit(addWhitelistDomain); | 37 $("#whitelistForm").submit(addWhitelistDomain); |
26 $("#removeWhitelist").click(removeSelectedExcludedDomain); | 38 $("#removeWhitelist").click(removeSelectedExcludedDomain); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 { | 141 { |
130 var selectedIndex = 0; | 142 var selectedIndex = 0; |
131 var selectedPrefix = null; | 143 var selectedPrefix = null; |
132 var matchCount = 0; | 144 var matchCount = 0; |
133 | 145 |
134 var list = document.getElementById("subscriptionSelector"); | 146 var list = document.getElementById("subscriptionSelector"); |
135 var elements = request.responseXML.documentElement.getElementsByTagName("sub
scription"); | 147 var elements = request.responseXML.documentElement.getElementsByTagName("sub
scription"); |
136 for (var i = 0; i < elements.length; i++) | 148 for (var i = 0; i < elements.length; i++) |
137 { | 149 { |
138 var element = elements[i]; | 150 var element = elements[i]; |
139 var option = document.createElement("option"); | 151 var option = new Option(); |
140 option.text = element.getAttribute("title") + " (" + element.getAttribute(
"specialization") + ")"; | 152 option.text = element.getAttribute("title") + " (" + element.getAttribute(
"specialization") + ")"; |
141 option._data = { | 153 option._data = { |
142 title: element.getAttribute("title"), | 154 title: element.getAttribute("title"), |
143 url: element.getAttribute("url"), | 155 url: element.getAttribute("url"), |
144 homepage: element.getAttribute("homepage") | 156 homepage: element.getAttribute("homepage") |
145 }; | 157 }; |
146 | 158 |
147 var prefix = require("utils").Utils.checkLocalePrefixMatch(element.getAttr
ibute("prefixes")); | 159 var prefix = require("utils").Utils.checkLocalePrefixMatch(element.getAttr
ibute("prefixes")); |
148 if (prefix) | 160 if (prefix) |
149 { | 161 { |
(...skipping 17 matching lines...) Expand all Loading... |
167 if (Math.random() * matchCount < 1) | 179 if (Math.random() * matchCount < 1) |
168 { | 180 { |
169 selectedIndex = i; | 181 selectedIndex = i; |
170 selectedPrefix = prefix; | 182 selectedPrefix = prefix; |
171 } | 183 } |
172 } | 184 } |
173 } | 185 } |
174 list.appendChild(option); | 186 list.appendChild(option); |
175 } | 187 } |
176 | 188 |
177 var option = document.createElement("option"); | 189 var option = new Option(); |
178 option.text = i18n.getMessage("filters_addSubscriptionOther_label") + "\u202
6"; | 190 option.text = i18n.getMessage("filters_addSubscriptionOther_label") + "\u202
6"; |
179 option._data = null; | 191 option._data = null; |
180 list.appendChild(option); | 192 list.appendChild(option); |
181 | 193 |
182 list.selectedIndex = selectedIndex; | 194 list.selectedIndex = selectedIndex; |
183 | 195 |
184 if (delayedSubscriptionSelection) | 196 if (delayedSubscriptionSelection) |
185 startSubscriptionSelection.apply(null, delayedSubscriptionSelection); | 197 startSubscriptionSelection.apply(null, delayedSubscriptionSelection); |
186 }; | 198 }; |
187 request.send(null); | 199 request.send(null); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 case "subscription.title": | 360 case "subscription.title": |
349 case "subscription.disabled": | 361 case "subscription.disabled": |
350 case "subscription.homepage": | 362 case "subscription.homepage": |
351 case "subscription.lastDownload": | 363 case "subscription.lastDownload": |
352 case "subscription.downloadStatus": | 364 case "subscription.downloadStatus": |
353 var element = findSubscriptionElement(item); | 365 var element = findSubscriptionElement(item); |
354 if (element) | 366 if (element) |
355 updateSubscriptionInfo(element); | 367 updateSubscriptionInfo(element); |
356 break; | 368 break; |
357 case "subscription.added": | 369 case "subscription.added": |
358 if (!(item instanceof SpecialSubscription) && !findSubscriptionElement(ite
m)) | 370 if (item instanceof SpecialSubscription) |
359 { | 371 { |
360 if (item.url == Prefs.subscriptions_exceptionsurl) | 372 for (var i = 0; i < item.filters.length; i++) |
361 $("#acceptableAds").prop("checked", true); | 373 onFilterChange("filter.added", item.filters[i]); |
362 else | |
363 addSubscriptionEntry(item); | |
364 } | 374 } |
| 375 else if (item.url == Prefs.subscriptions_exceptionsurl) |
| 376 $("#acceptableAds").prop("checked", true); |
| 377 else if (!findSubscriptionElement(item)) |
| 378 addSubscriptionEntry(item); |
365 break; | 379 break; |
366 case "subscription.removed": | 380 case "subscription.removed": |
367 if (item.url == Prefs.subscriptions_exceptionsurl) | 381 if (item instanceof SpecialSubscription) |
| 382 { |
| 383 for (var i = 0; i < item.filters.length; i++) |
| 384 onFilterChange("filter.removed", item.filters[i]); |
| 385 } |
| 386 else if (item.url == Prefs.subscriptions_exceptionsurl) |
368 $("#acceptableAds").prop("checked", false); | 387 $("#acceptableAds").prop("checked", false); |
369 else | 388 else |
370 { | 389 { |
371 var element = findSubscriptionElement(item); | 390 var element = findSubscriptionElement(item); |
372 if (element) | 391 if (element) |
373 element.parentNode.removeChild(element); | 392 element.parentNode.removeChild(element); |
374 } | 393 } |
375 break; | 394 break; |
376 case "filter.added": | 395 case "filter.added": |
377 if (item instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/.tes
t(item.text)) | 396 if (item instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/.tes
t(item.text)) |
(...skipping 13 matching lines...) Expand all Loading... |
391 // Populates a list box with a number of entries | 410 // Populates a list box with a number of entries |
392 function populateList(id, entries) | 411 function populateList(id, entries) |
393 { | 412 { |
394 var list = document.getElementById(id); | 413 var list = document.getElementById(id); |
395 while (list.lastChild) | 414 while (list.lastChild) |
396 list.removeChild(list.lastChild); | 415 list.removeChild(list.lastChild); |
397 | 416 |
398 entries.sort(); | 417 entries.sort(); |
399 for (var i = 0; i < entries.length; i++) | 418 for (var i = 0; i < entries.length; i++) |
400 { | 419 { |
401 var option = document.createElement("option"); | 420 var option = new Option(); |
402 option.text = entries[i]; | 421 option.text = entries[i]; |
403 option.value = entries[i]; | 422 option.value = entries[i]; |
404 list.appendChild(option); | 423 list.appendChild(option); |
405 } | 424 } |
406 } | 425 } |
407 | 426 |
408 // Add a filter string to the list box. | 427 // Add a filter string to the list box. |
409 function appendToListBox(boxId, text) | 428 function appendToListBox(boxId, text) |
410 { | 429 { |
411 var elt = document.createElement("option"); | 430 var elt = new Option(); /* Note: document.createElement("option") is unreliab
le in Opera */ |
412 elt.text = text; | 431 elt.text = text; |
413 elt.value = text; | 432 elt.value = text; |
414 document.getElementById(boxId).appendChild(elt); | 433 document.getElementById(boxId).appendChild(elt); |
415 } | 434 } |
416 | 435 |
417 // Remove a filter string from a list box. | 436 // Remove a filter string from a list box. |
418 function removeFromListBox(boxId, text) | 437 function removeFromListBox(boxId, text) |
419 { | 438 { |
420 var elt = document.createElement("option"); | |
421 elt.text = text; | |
422 elt.value = text; | |
423 var list = document.getElementById(boxId); | 439 var list = document.getElementById(boxId); |
424 for (var i = 0; i < list.length; i++) | 440 for (var i = 0; i < list.length; i++) |
425 if (list.options[i].value == text) | 441 if (list.options[i].value == text) |
426 list.remove(i--); | 442 list.remove(i--); |
427 } | 443 } |
428 | 444 |
429 function addWhitelistDomain(event) | 445 function addWhitelistDomain(event) |
430 { | 446 { |
431 event.preventDefault(); | 447 event.preventDefault(); |
432 | 448 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 if (subscription.disabled == !enabled.checked) | 591 if (subscription.disabled == !enabled.checked) |
576 return; | 592 return; |
577 | 593 |
578 subscription.disabled = !enabled.checked; | 594 subscription.disabled = !enabled.checked; |
579 }, false); | 595 }, false); |
580 | 596 |
581 updateSubscriptionInfo(element); | 597 updateSubscriptionInfo(element); |
582 | 598 |
583 document.getElementById("filterLists").appendChild(element); | 599 document.getElementById("filterLists").appendChild(element); |
584 } | 600 } |
OLD | NEW |