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

Delta Between Two Patch Sets: lib/snippets.js

Issue 29737558: Issue 6538, 6781 - Implement support for snippet filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created March 30, 2018, 8:18 p.m.
Right Patch Set: Improve comment formatting Created July 11, 2018, 1:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
LEFTRIGHT
(no file at all)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 "use strict";
19
20 /**
21 * @fileOverview Snippets implementation.
22 */
23
24 const {Filter} = require("./filterClasses");
25
26 let filters = new Set();
27
28 /**
29 * Container for snippet filters
30 * @class
31 */
32 let Snippets = {
33 /**
34 * Removes all known filters
35 */
36 clear()
37 {
38 filters.clear();
39 },
40
41 /**
42 * Add a new snippet filter
43 * @param {SnippetFilter} filter
44 */
45 add(filter)
46 {
47 filters.add(filter.text);
48 },
49
50 /**
51 * Removes a snippet filter
52 * @param {SnippetFilter} filter
53 */
54 remove(filter)
55 {
56 filters.delete(filter.text);
57 },
58
59 /**
60 * Returns a list of all scripts active on a particular domain
61 * @param {string} domain
62 * @return {string[]}
63 */
64 getScriptsForDomain(domain)
65 {
66 let result = [];
67 for (let text of filters)
68 {
69 let filter = Filter.fromText(text);
70 if (filter.isActiveOnDomain(domain))
71 result.push(filter.script);
72 }
73 return result;
74 }
75 };
76
77 exports.Snippets = Snippets;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld