trackers module

This commit is contained in:
Andrey Meshkov
2018-10-12 14:23:41 +03:00
committed by Ildar Kamalov
parent 11e8853a34
commit 5fb603f6c9
5 changed files with 7350 additions and 3 deletions

View 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;
};

File diff suppressed because it is too large Load Diff