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: Make snippet filters similar to element hiding filters Created April 25, 2018, 5:15 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 /** 20 /**
21 * @fileOverview Snippets implementation. 21 * @fileOverview Snippets implementation.
Manish Jethani 2018/04/26 13:19:17 This is almost exactly like lib/elemHideEmulation.
22 */ 22 */
23 23
24 const {ElemHide} = require("./elemHide");
25 const {Filter} = require("./filterClasses"); 24 const {Filter} = require("./filterClasses");
26 25
27 let filters = new Set(); 26 let filters = new Set();
28 27
29 /** 28 /**
30 * Container for snippet filters 29 * Container for snippet filters
31 * @class 30 * @class
32 */ 31 */
33 let Snippets = { 32 let Snippets = {
34 /** 33 /**
(...skipping 18 matching lines...) Expand all
53 * @param {SnippetFilter} filter 52 * @param {SnippetFilter} filter
54 */ 53 */
55 remove(filter) 54 remove(filter)
56 { 55 {
57 filters.delete(filter.text); 56 filters.delete(filter.text);
58 }, 57 },
59 58
60 /** 59 /**
61 * Returns a list of all scripts active on a particular domain 60 * Returns a list of all scripts active on a particular domain
62 * @param {string} domain 61 * @param {string} domain
63 * @return {SnippetFilter[]} 62 * @return {string[]}
64 */ 63 */
65 getScriptsForDomain(domain) 64 getScriptsForDomain(domain)
66 { 65 {
67 let result = []; 66 let result = [];
68 for (let text of filters) 67 for (let text of filters)
69 { 68 {
70 let filter = Filter.fromText(text); 69 let filter = Filter.fromText(text);
71 if (filter.isActiveOnDomain(domain) && 70 if (filter.isActiveOnDomain(domain))
72 !ElemHide.getException(filter, domain)) 71 result.push(filter.script);
Manish Jethani 2018/04/26 13:19:16 Note: We're using ElemHide exceptions here. I feel
73 {
74 result.push(filter);
75 }
76 } 72 }
77 return result; 73 return result;
78 } 74 }
79 }; 75 };
80 76
81 exports.Snippets = Snippets; 77 exports.Snippets = Snippets;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld