Skip to content

Instantly share code, notes, and snippets.

@kzar
Last active September 15, 2016 09:42
Show Gist options
  • Save kzar/ef5df1e7da33272111789a755a0db164 to your computer and use it in GitHub Desktop.
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 )
"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