I'm learning Map() function of javascript. I want to map rules for declarativeNetRequest but I need a bit of help.
How I can create a map using this model as output:
{
"id" : 1,
"priority": 1,
"action" : { "type" : "block" },
"condition" : {
"urlFilter" : "abc",
"domains" : ["foo.com"],
"resourceTypes" : ["script"]
}
}
At the moment I'm fetching a list of filters from a remote server and I'm parsing it using this code, after the parsing I want to map the results to have an object that I can use with declarativeNetrequest api
let def = {};
let out;
let defMap = new Map();
const fetch = async () => {
await axios({
url: "https://raw.githubusercontent.com/easylist/easylist/master/easylist/easylist_adservers.txt",
responseType: "text"
})
.then( (response) => {
let parsed = response.data.split("\n");
out = parsed.filter( (item) => {
if( !item.startsWith("!") ){
return item.replace(/([\|\|\w\d\.\^]+)(?:[\w-\?=~,\$]+)$.*/, "$1");
}
});
});
return out;
}
// debug only
fetch().then( (out) => {
console.log(out);
});
will be this possible?