Commit 96376a4b authored by Aral Balkan's avatar Aral Balkan
Browse files

Stats: Collating Google domains off by default for trackers

(To turn it on, pass --google. On by default if called without
commandline arguments.)
parent b9985ce8
......@@ -50,10 +50,10 @@ class Statistics
@googleCount = 0
@generateIfNecessary: ->
@generateIfNecessary: (collateGoogle = false) ->
# Asynchronous singleton access
if @instance != null then return (Promise.resolve @instance)
@generateStatistics().then => @instance = new @
@generateStatistics(collateGoogle).then => @instance = new @
#
......@@ -73,10 +73,12 @@ class Statistics
@googleCount = Statistics.googleCount
@generateStatistics: =>
@generateStatistics: (collateGoogle = false) =>
draftSitesPath = path.join path.homedir(), 'better.fyi', 'drafts', 'sites'
trackersRegExp = new RegExp "<!-- trackersList -->([\\s\\S]*?)<!-- \\/trackersList -->", 'm'
domainsAlsoOwnedByGoogle = ['gstatic.com', 'doubleclick.net', 'youtube.com']
if collateGoogle
domainsAlsoOwnedByGoogle = ['gstatic.com', 'doubleclick.net', 'youtube.com']
ContentIndex.generateIfNecessary().then (contentIndex) =>
Promise.each contentIndex.draftSites, (draftSite) =>
......@@ -100,17 +102,18 @@ class Statistics
trackersOnThisSite++
if @sitesPerTracker[line] == undefined then @sitesPerTracker[line] = 1 else @sitesPerTracker[line]++
# Google count
if ((line.indexOf 'google') != -1) or (line in domainsAlsoOwnedByGoogle)
localGoogleCount++
@googleDomains.add line
if collateGoogle
# Google count
if ((line.indexOf 'google') != -1) or (line in domainsAlsoOwnedByGoogle)
localGoogleCount++
@googleDomains.add line
# Save the number of trackers found on this site
@trackersPerSite[draftSite] = trackersOnThisSite
if localGoogleCount > 0 then @googleCount++
@sitesPerTracker['All Google'] = @googleCount
if collateGoogle
if localGoogleCount > 0 then @googleCount++
@sitesPerTracker['All Google'] = @googleCount
.then =>
#
# Order the tracker counter
......
......@@ -24,7 +24,7 @@ args = (require 'minimist') process.argv.slice(2), {boolean: true}
if (not args.all) and (not args.trackers) and (not args.sites)
args.all = true
Statistics.generateIfNecessary().then (statistics) ->
Statistics.generateIfNecessary(args.all || args.google).then (statistics) ->
if args.all or args.trackers
_ "\nTrackers by popularity:\n"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment