Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: options.js

Issue 8432019: Added acceptable ads list to the options UI (Closed)
Patch Set: Created Sept. 25, 2012, 2:18 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « options.html ('k') | update_locales.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: options.js
===================================================================
--- a/options.js
+++ b/options.js
@@ -1,29 +1,34 @@
var backgroundPage = chrome.extension.getBackgroundPage();
var imports = ["FilterStorage", "FilterNotifier", "Subscription", "SpecialSubscription",
"DownloadableSubscription", "Filter", "WhitelistFilter",
- "Synchronizer", "require"];
+ "Synchronizer", "Prefs", "Utils", "require"];
for (var i = 0; i < imports.length; i++)
window[imports[i]] = backgroundPage[imports[i]];
// Loads options from localStorage and sets UI elements accordingly
function loadOptions()
{
loadI18nStrings();
// Set page title to i18n version of "Adblock Plus Options"
document.title = chrome.i18n.getMessage("options");
+ // Set links
+ $("#acceptableAdsLink").attr("href", Prefs.subscriptions_exceptionsurl);
+ $("#acceptableAdsDocs").attr("href", Prefs.documentation_link.replace(/%LINK%/g, "acceptable_ads").replace(/%LANG%/g, Utils.appLocale));
+
// Add event listeners
window.addEventListener("unload", unloadOptions, false);
$("#updateFilterLists").click(updateFilterLists);
$("#startSubscriptionSelection").click(startSubscriptionSelection);
$("#subscriptionSelector").change(updateSubscriptionSelection);
$("#addSubscription").click(addSubscription);
+ $("#acceptableAds").click(allowAcceptableAds);
$("#whitelistForm").submit(addWhitelistDomain);
$("#removeWhitelist").click(removeSelectedExcludedDomain);
$("#customFilterForm").submit(addTypedFilter);
$("#removeCustomFilter").click(removeSelectedFilters);
$("#rawFiltersButton").click(toggleFiltersInRawFormat);
$("#importRawFilters").click(importRawFiltersText);
FilterNotifier.addListener(onFilterChange);
@@ -51,25 +56,34 @@ function loadOptions()
// Reloads the displayed subscriptions and filters
function reloadFilters()
{
// Load user filter URLs
var container = document.getElementById("filterLists");
while (container.lastChild)
container.removeChild(container.lastChild);
+ var hasAcceptable = false;
for (var i = 0; i < FilterStorage.subscriptions.length; i++)
{
var subscription = FilterStorage.subscriptions[i];
if (subscription instanceof SpecialSubscription)
continue;
+ if (subscription.url == Prefs.subscriptions_exceptionsurl)
+ {
+ hasAcceptable = true;
+ continue;
+ }
+
addSubscriptionEntry(subscription);
}
+ $("#acceptableAds").prop("checked", hasAcceptable);
+
// User-entered filters
showUserFilters();
}
// Cleans up when the options window is closed
function unloadOptions()
{
FilterNotifier.removeListener(onFilterChange);
@@ -254,16 +268,34 @@ function doAddSubscription(url, title, h
if (homepage)
subscription.homepage = homepage;
FilterStorage.addSubscription(subscription);
if (subscription instanceof DownloadableSubscription && !subscription.lastDownload)
Synchronizer.execute(subscription);
}
+function allowAcceptableAds(event)
+{
+ var subscription = Subscription.fromURL(Prefs.subscriptions_exceptionsurl);
+ if (!subscription)
+ return;
+
+ subscription.disabled = false;
+ subscription.title = "Allow non-intrusive advertising";
+ if ($("#acceptableAds").prop("checked"))
+ {
+ FilterStorage.addSubscription(subscription);
+ if (subscription instanceof DownloadableSubscription && !subscription.lastDownload)
+ Synchronizer.execute(subscription);
+ }
+ else
+ FilterStorage.removeSubscription(subscription);
+}
+
function findSubscriptionElement(subscription)
{
var children = document.getElementById("filterLists").childNodes;
for (var i = 0; i < children.length; i++)
if (children[i]._subscription == subscription)
return children[i];
return null;
}
@@ -323,22 +355,32 @@ function onFilterChange(action, item, pa
case "subscription.lastDownload":
case "subscription.downloadStatus":
var element = findSubscriptionElement(item);
if (element)
updateSubscriptionInfo(element);
break;
case "subscription.added":
if (!(item instanceof SpecialSubscription) && !findSubscriptionElement(item))
- addSubscriptionEntry(item);
+ {
+ if (item.url == Prefs.subscriptions_exceptionsurl)
+ $("#acceptableAds").prop("checked", true);
+ else
+ addSubscriptionEntry(item);
+ }
break;
case "subscription.removed":
- var element = findSubscriptionElement(item);
- if (element)
- element.parentNode.removeChild(element);
+ if (item.url == Prefs.subscriptions_exceptionsurl)
+ $("#acceptableAds").prop("checked", false);
+ else
+ {
+ var element = findSubscriptionElement(item);
+ if (element)
+ element.parentNode.removeChild(element);
+ }
break;
case "filter.added":
if (item instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/.test(item.text))
appendToListBox("excludedDomainsBox", RegExp.$1);
else
appendToListBox("userFiltersBox", item.text);
break;
case "filter.removed":
« no previous file with comments | « options.html ('k') | update_locales.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld