Last active
September 15, 2016 09:42
-
-
Save kzar/ef5df1e7da33272111789a755a0db164 to your computer and use it in GitHub Desktop.
Small Node.js script to strip document blocking rules. (See https://issues.adblockplus.org/ticket/4280 )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
let fs = require("fs"); | |
if (process.argv.length != 3) | |
{ | |
console.log("Usage: nodejs strip.js filename.json"); | |
process.exit(1); | |
} | |
let filename = process.argv[2]; | |
fs.readFile(filename, "utf8", (error, data) => | |
{ | |
if (error) | |
{ | |
console.log(error); | |
process.exit(1); | |
} | |
let stripped = JSON.stringify( | |
JSON.parse(data).map(rule => | |
{ | |
if (rule.action.type != "block") | |
return rule; | |
let resource_type = rule.trigger["resource-type"]; | |
let document_index = resource_type.indexOf("document"); | |
if (document_index > -1) | |
resource_type.splice(document_index, 1); | |
return resource_type.length == 0 ? null : rule; | |
}).filter(rule => rule != null) | |
, null, "\t"); | |
fs.writeFile(filename, stripped, error => | |
{ | |
if (error) | |
{ | |
console.log(error); | |
process.exit(1); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment