This repository has been archived by the owner on Mar 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
genDataFile.js
81 lines (75 loc) · 2.25 KB
/
genDataFile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* Copyright (c) 2016 Sergiy Zhukovs'kyy. Distributed under the MPL2 license.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var CTPParser = require('../build/Release/tp_node_addon').CTPParser;
var fs = require('fs');
var data = fs.readFileSync('../data/disconnect.json');
var addon = new CTPParser();
var mapObjects = new Map();
var values = new Map();
var previousKey = undefined;
var previousValue = undefined;
var addToList = true;
JSON.parse(String(data), function(k, v) {
// We shouldn't add all section after Advertising, which is Content
if (k == 'Advertising') {
addToList = false;
//console.log(k);
}
else if (k == 'Content') {
addToList = true;
console.log(k);
}
//console.log(k);
if (k.indexOf('http://') == 0 || k.indexOf('https://') == 0) {
var existingValues = mapObjects.get(k);
if (undefined == existingValues) {
existingValues = values;
}
else {
for (var key of values.keys()) {
existingValues.set(key);
}
}
if (undefined != existingValues && 0 != existingValues.size) {
mapObjects.set(k, existingValues);
}
values = new Map();
previousKey = undefined;
previousValue = undefined;
} else if (!isNaN(k)) {
if (!addToList) {
console.log(v);
return;
}
if (undefined != previousKey && parseInt(k) <= parseInt(previousKey)) {
values.delete(previousValue);
}
values.set(v);
previousKey = k;
previousValue = v;
} else {
values = new Map();
previousKey = undefined;
previousValue = undefined;
}
});
for (var [key, value] of mapObjects) {
var keyValues = undefined;
for (var key1 of value.keys()) {
if (undefined != keyValues) {
keyValues += ',';
keyValues += key1;
} else {
keyValues = key1;
}
addon.addTracker(key1);
}
addon.addFirstPartyHosts(key, keyValues);
console.log(key + " = " + keyValues);
}
var serializedObject = addon.serialize();
console.log('serializedObject == ' + serializedObject);
console.log('size == ' + serializedObject.length);
fs.writeFileSync('../data/TrackingProtection.dat', serializedObject);