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

Side by Side Diff: abp2blocklist.js

Issue 29328931: Issue 3176 - Keep filter list parameters (Closed)
Patch Set: Created Oct. 7, 2015, 7:49 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 var readline = require("readline"); 1 var readline = require("readline");
2 var punycode = require("punycode"); 2 var punycode = require("punycode");
3 var tldjs = require("tldjs"); 3 var tldjs = require("tldjs");
4 var filterClasses = require("./adblockplus.js"); 4 var filterClasses = require("./adblockplus.js");
5 5
6 var typeMap = filterClasses.RegExpFilter.typeMap; 6 var typeMap = filterClasses.RegExpFilter.typeMap;
7 7
8 var params = {};
8 var requestFilters = []; 9 var requestFilters = [];
9 var requestExceptions = []; 10 var requestExceptions = [];
10 var elemhideFilters = []; 11 var elemhideFilters = [];
11 var elemhideExceptions = []; 12 var elemhideExceptions = [];
12 var elemhideSelectorExceptions = Object.create(null); 13 var elemhideSelectorExceptions = Object.create(null);
13 14
14 function recordException(filter) { 15 function recordException(filter) {
15 if (filter.contentType & (typeMap.IMAGE 16 if (filter.contentType & (typeMap.IMAGE
16 | typeMap.STYLESHEET 17 | typeMap.STYLESHEET
17 | typeMap.SCRIPT 18 | typeMap.SCRIPT
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 if (filter instanceof filterClasses.BlockingFilter) 63 if (filter instanceof filterClasses.BlockingFilter)
63 requestFilters.push(filter); 64 requestFilters.push(filter);
64 if (filter instanceof filterClasses.WhitelistFilter) 65 if (filter instanceof filterClasses.WhitelistFilter)
65 recordException(filter); 66 recordException(filter);
66 if (filter instanceof filterClasses.ElemHideFilter) 67 if (filter instanceof filterClasses.ElemHideFilter)
67 elemhideFilters.push(filter); 68 elemhideFilters.push(filter);
68 if (filter instanceof filterClasses.ElemHideException) 69 if (filter instanceof filterClasses.ElemHideException)
69 recordSelectorException(filter); 70 recordSelectorException(filter);
70 } 71 }
71 72
73 function parseLine(line) {
74 var paramMatch = /^\s*!\s*([\w ]+)\s*:\s*(.*)/.exec(line);
Sebastian Noack 2015/10/13 11:25:08 I think we should leave the parsing to the core co
75 if (paramMatch) {
76 var key = paramMatch[1];
77 var paramsToKeep = ["version", "title", "last modified", "expire s", "homepage", "licence"];
78 if (paramsToKeep.indexOf(key.toLowerCase()) != -1)
79 params[key] = paramMatch[2];
80 return;
81 }
82 parseFilter(line);
83 }
84
72 function escapeRegExp(s) { 85 function escapeRegExp(s) {
73 return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); 86 return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
74 } 87 }
75 88
76 function matchDomain(domain) { 89 function matchDomain(domain) {
77 return "^https?://([^/:]*\\.)?" + escapeRegExp(domain) + "[/:]"; 90 return "^https?://([^/:]*\\.)?" + escapeRegExp(domain) + "[/:]";
78 } 91 }
79 92
80 function convertElemHideFilter(filter) { 93 function convertElemHideFilter(filter) {
81 var included = []; 94 var included = [];
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 271
259 for (i = 0; i < elemhideFilters.length; i++) 272 for (i = 0; i < elemhideFilters.length; i++)
260 convertElemHideFilter(elemhideFilters[i]).forEach(addRule); 273 convertElemHideFilter(elemhideFilters[i]).forEach(addRule);
261 for (i = 0; i < elemhideExceptions.length; i++) 274 for (i = 0; i < elemhideExceptions.length; i++)
262 addRule(convertFilter(elemhideExceptions[i], "ignore-previous-ru les", false)); 275 addRule(convertFilter(elemhideExceptions[i], "ignore-previous-ru les", false));
263 for (i = 0; i < requestFilters.length; i++) 276 for (i = 0; i < requestFilters.length; i++)
264 addRule(convertFilter(requestFilters[i], "block", true)); 277 addRule(convertFilter(requestFilters[i], "block", true));
265 for (i = 0; i < requestExceptions.length; i++) 278 for (i = 0; i < requestExceptions.length; i++)
266 addRule(convertFilter(requestExceptions[i], "ignore-previous-rul es", true)); 279 addRule(convertFilter(requestExceptions[i], "ignore-previous-rul es", true));
267 280
281 for (key in params)
282 if (params.hasOwnProperty(key))
283 console.log("// " + key + ": " + params[key]);
Sebastian Noack 2015/10/13 11:25:08 But anyway, valid JSON cannot have comments. So NO
Felix Dahlke 2015/10/13 11:37:26 Did you read https://issues.adblockplus.org/ticket
Felix Dahlke 2015/10/13 11:52:15 But well, different approaches shouldn't be discus
268 console.log(JSON.stringify(rules, null, "\t")); 284 console.log(JSON.stringify(rules, null, "\t"));
269 } 285 }
270 286
271 var rl = readline.createInterface({input: process.stdin, terminal: false}); 287 var rl = readline.createInterface({input: process.stdin, terminal: false});
272 rl.on("line", parseFilter); 288 rl.on("line", parseLine);
273 rl.on("close", logRules); 289 rl.on("close", logRules);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld