trackers module
This commit is contained in:
parent
11e8853a34
commit
5fb603f6c9
44
client/src/helpers/whotracksme.js
Normal file
44
client/src/helpers/whotracksme.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import trackersDb from './whotracksmedb.json';
|
||||||
|
|
||||||
|
/**
|
||||||
|
@typedef TrackerData
|
||||||
|
@type {object}
|
||||||
|
@property {string} id - tracker ID.
|
||||||
|
@property {string} name - tracker name.
|
||||||
|
@property {number} age - tracker category.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets tracker data in the whotracksme database
|
||||||
|
*
|
||||||
|
* @param {String} domainName domain name to check
|
||||||
|
* @returns {TrackerData} tracker data or null if no matching tracker found
|
||||||
|
*/
|
||||||
|
export const getTrackerData = (domainName) => {
|
||||||
|
if (!domainName) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parts = domainName.split(/\./g).reverse();
|
||||||
|
let hostToCheck = '';
|
||||||
|
|
||||||
|
// Check every subdomain except the TLD
|
||||||
|
for (let i = 1; i < parts.length; i += 1) {
|
||||||
|
hostToCheck = hostToCheck + (i > 0 ? '.' : '') + parts[i];
|
||||||
|
const trackerId = trackersDb.trackerDomains[hostToCheck];
|
||||||
|
|
||||||
|
if (trackerId) {
|
||||||
|
const trackerData = trackersDb.trackers[trackerId];
|
||||||
|
const categoryName = trackersDb.categories[trackerData.categoryId];
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: trackerId,
|
||||||
|
name: trackerData.name,
|
||||||
|
category: categoryName,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// No tracker found for the specified domain
|
||||||
|
return null;
|
||||||
|
};
|
7303
client/src/helpers/whotracksmedb.json
Normal file
7303
client/src/helpers/whotracksmedb.json
Normal file
File diff suppressed because it is too large
Load Diff
2
scripts/whotracksme/.gitignore
vendored
2
scripts/whotracksme/.gitignore
vendored
@ -1,2 +1,2 @@
|
|||||||
node_modules
|
node_modules
|
||||||
whotracksme.json
|
whotracksmedb.json
|
@ -9,4 +9,4 @@ yarn install
|
|||||||
yarn index.js
|
yarn index.js
|
||||||
```
|
```
|
||||||
|
|
||||||
You'll find the output in the `whotracksme.json` file.
|
You'll find the output in the `whotracksmedb.json` file.
|
@ -3,7 +3,7 @@ const sqlite3 = require('sqlite3').verbose();
|
|||||||
const downloadFileSync = require('download-file-sync');
|
const downloadFileSync = require('download-file-sync');
|
||||||
|
|
||||||
const INPUT_SQL_URL = 'https://raw.githubusercontent.com/cliqz-oss/whotracks.me/master/whotracksme/data/assets/trackerdb.sql';
|
const INPUT_SQL_URL = 'https://raw.githubusercontent.com/cliqz-oss/whotracks.me/master/whotracksme/data/assets/trackerdb.sql';
|
||||||
const OUTPUT_PATH = 'whotracksme.json';
|
const OUTPUT_PATH = 'whotracksmedb.json';
|
||||||
|
|
||||||
console.log('Downloading ' + INPUT_SQL_URL);
|
console.log('Downloading ' + INPUT_SQL_URL);
|
||||||
let trackersDbSql = downloadFileSync(INPUT_SQL_URL).toString();
|
let trackersDbSql = downloadFileSync(INPUT_SQL_URL).toString();
|
||||||
|
Loading…
Reference in New Issue
Block a user