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

Unified Diff: lib/api.js

Issue 29545700: Issue 5685 - Pass ESLint (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Address review comments Created Sept. 18, 2017, 12:42 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 | « lib/.eslintrc.json ('k') | lib/compat.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/api.js
===================================================================
--- a/lib/api.js
+++ b/lib/api.js
@@ -10,215 +10,222 @@
* 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/>.
*/
-var API = (function()
+"use strict";
+
+let API = (() =>
{
const {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
- var Filter = require("filterClasses").Filter;
- var Subscription = require("subscriptionClasses").Subscription;
- var SpecialSubscription = require("subscriptionClasses").SpecialSubscription;
- var FilterStorage = require("filterStorage").FilterStorage;
- var defaultMatcher = require("matcher").defaultMatcher;
- var ElemHide = require("elemHide").ElemHide;
- var Synchronizer = require("synchronizer").Synchronizer;
- var Prefs = require("prefs").Prefs;
- var checkForUpdates = require("updater").checkForUpdates;
- var Notification = require("notification").Notification;
+ const {Filter} = require("filterClasses");
+ const {Subscription} = require("subscriptionClasses");
+ const {SpecialSubscription} = require("subscriptionClasses");
+ const {FilterStorage} = require("filterStorage");
+ const {defaultMatcher} = require("matcher");
+ const {ElemHide} = require("elemHide");
+ const {Synchronizer} = require("synchronizer");
+ const {Prefs} = require("prefs");
+ const {checkForUpdates} = require("updater");
+ const {Notification} = require("notification");
return {
- getFilterFromText: function(text)
+ getFilterFromText(text)
{
text = Filter.normalize(text);
if (!text)
throw "Attempted to create a filter from empty text";
return Filter.fromText(text);
},
- isListedFilter: function(filter)
+ isListedFilter(filter)
{
- return filter.subscriptions.some(function(s)
+ return filter.subscriptions.some(s =>
{
return (s instanceof SpecialSubscription && !s.disabled);
});
},
- addFilterToList: function(filter)
+ addFilterToList(filter)
{
FilterStorage.addFilter(filter);
},
- removeFilterFromList: function(filter)
+ removeFilterFromList(filter)
{
FilterStorage.removeFilter(filter);
},
- getListedFilters: function()
+ getListedFilters()
{
- var filters = {};
- for (var i = 0; i < FilterStorage.subscriptions.length; i++)
+ let filters = {};
+ for (let i = 0; i < FilterStorage.subscriptions.length; i++)
{
- var subscription = FilterStorage.subscriptions[i];
+ let subscription = FilterStorage.subscriptions[i];
if (subscription instanceof SpecialSubscription)
{
- for (var j = 0; j < subscription.filters.length; j++)
+ for (let j = 0; j < subscription.filters.length; j++)
{
- var filter = subscription.filters[j];
+ let filter = subscription.filters[j];
if (!(filter.text in filters))
filters[filter.text] = filter;
}
}
}
- return Object.keys(filters).map(function(k)
+ return Object.keys(filters).map(k =>
{
return filters[k];
});
},
- getSubscriptionFromUrl: function(url)
+ getSubscriptionFromUrl(url)
{
return Subscription.fromURL(url);
},
- isListedSubscription: function(subscription)
+ isListedSubscription(subscription)
{
return subscription.url in FilterStorage.knownSubscriptions;
},
- addSubscriptionToList: function(subscription)
+ addSubscriptionToList(subscription)
{
FilterStorage.addSubscription(subscription);
if (!subscription.lastDownload)
Synchronizer.execute(subscription);
},
- removeSubscriptionFromList: function(subscription)
+ removeSubscriptionFromList(subscription)
{
FilterStorage.removeSubscription(subscription);
},
- updateSubscription: function(subscription)
+ updateSubscription(subscription)
{
Synchronizer.execute(subscription);
},
- isSubscriptionUpdating: function(subscription)
+ isSubscriptionUpdating(subscription)
{
return Synchronizer.isExecuting(subscription.url);
},
- getListedSubscriptions: function()
+ getListedSubscriptions()
{
- return FilterStorage.subscriptions.filter(function(s)
+ return FilterStorage.subscriptions.filter(s =>
{
- return !(s instanceof SpecialSubscription)
+ return !(s instanceof SpecialSubscription);
});
},
- getRecommendedSubscriptions: function()
+ getRecommendedSubscriptions()
{
- var subscriptions = require("subscriptions.xml");
- var result = [];
- for (var i = 0; i < subscriptions.length; i++)
+ let subscriptions = require("subscriptions.xml");
+ let result = [];
+ for (let i = 0; i < subscriptions.length; i++)
{
- var subscription = Subscription.fromURL(subscriptions[i].url);
+ let subscription = Subscription.fromURL(subscriptions[i].url);
subscription.title = subscriptions[i].title;
subscription.homepage = subscriptions[i].homepage;
// These aren't normally properties of a Subscription object
subscription.author = subscriptions[i].author;
subscription.prefixes = subscriptions[i].prefixes;
subscription.specialization = subscriptions[i].specialization;
result.push(subscription);
}
return result;
},
- isAASubscription: function(subscription)
+ isAASubscription(subscription)
{
return subscription.url == Prefs.subscriptions_exceptionsurl;
},
- setAASubscriptionEnabled: function(enabled)
+ setAASubscriptionEnabled(enabled)
{
- var aaSubscription = FilterStorage.subscriptions.find(API.isAASubscription);
+ let aaSubscription = FilterStorage.subscriptions.find(
+ API.isAASubscription);
if (!enabled)
{
if (aaSubscription && !aaSubscription.disabled)
aaSubscription.disabled = true;
return;
}
if (!aaSubscription)
{
- aaSubscription = Subscription.fromURL(Prefs.subscriptions_exceptionsurl);
+ aaSubscription = Subscription.fromURL(
+ Prefs.subscriptions_exceptionsurl);
FilterStorage.addSubscription(aaSubscription);
}
if (aaSubscription.disabled)
aaSubscription.disabled = false;
if (!aaSubscription.lastDownload)
Synchronizer.execute(aaSubscription);
},
- isAASubscriptionEnabled: function()
+ isAASubscriptionEnabled()
{
- var aaSubscription = FilterStorage.subscriptions.find(API.isAASubscription);
+ let aaSubscription = FilterStorage.subscriptions.find(
+ API.isAASubscription);
return aaSubscription && !aaSubscription.disabled;
},
- showNextNotification: function(url)
+ showNextNotification(url)
{
Notification.showNext(url);
},
- getNotificationTexts: function(notification)
+ getNotificationTexts(notification)
{
return Notification.getLocalizedTexts(notification);
},
- markNotificationAsShown: function(id)
+ markNotificationAsShown(id)
{
Notification.markAsShown(id);
},
- checkFilterMatch: function(url, contentTypeMask, documentUrl)
+ checkFilterMatch(url, contentTypeMask, documentUrl)
{
- var requestHost = extractHostFromURL(url);
- var documentHost = extractHostFromURL(documentUrl);
- var thirdParty = isThirdParty(requestHost, documentHost);
- return defaultMatcher.matchesAny(url, contentTypeMask, documentHost, thirdParty);
+ let requestHost = extractHostFromURL(url);
+ let documentHost = extractHostFromURL(documentUrl);
+ let thirdParty = isThirdParty(requestHost, documentHost);
+ return defaultMatcher.matchesAny(
+ url, contentTypeMask, documentHost, thirdParty);
},
- getElementHidingSelectors: function(domain)
+ getElementHidingSelectors(domain)
{
- return ElemHide.getSelectorsForDomain(domain, ElemHide.ALL_MATCHING, false);
+ return ElemHide.getSelectorsForDomain(domain,
+ ElemHide.ALL_MATCHING, false);
},
- getPref: function(pref)
+ getPref(pref)
{
return Prefs[pref];
},
- setPref: function(pref, value)
+ setPref(pref, value)
{
Prefs[pref] = value;
},
- forceUpdateCheck: function(eventName)
+ forceUpdateCheck(eventName)
{
checkForUpdates(eventName ? _triggerEvent.bind(null, eventName) : null);
},
- getHostFromUrl: function(url)
+ getHostFromUrl(url)
{
return extractHostFromURL(url);
},
- compareVersions: function(v1, v2)
+ compareVersions(v1, v2)
{
return Services.vc.compare(v1, v2);
}
};
})();
« no previous file with comments | « lib/.eslintrc.json ('k') | lib/compat.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld