Skip to content

Commit

Permalink
issue dhowe#1717
Browse files Browse the repository at this point in the history
  • Loading branch information
cqx931 committed Aug 20, 2020
1 parent 05f276d commit 6d025ab
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 43 deletions.
6 changes: 5 additions & 1 deletion src/css/vault.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ body {
bottom: 0px;
left:-12px;
}
#desc {
display:block;
margin-bottom: 5px;
}
.myStatistics-panel{
display:none;
width:100%;
height:320px;
border:solid 1px #0076FF;
background-color:#0E1217;
padding:25px 15px;
padding:15px 15px 25px;
}
.myStatistics-label{
font-weight:700;
Expand Down
4 changes: 2 additions & 2 deletions src/js/adn/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@

const setCounts = function (ads, total, recent) {

const numVisits = visitedCount(ads) || 0;
const numVisits = recent ? 0 : (visitedCount(ads) || 0);
uDom('#vault-count').text(total || 0);

uDom('#visited').text(vAPI.i18n("adnMenuAdsClicked").replace("{{number}}", numVisits || 0));
Expand Down Expand Up @@ -336,7 +336,7 @@
.appendTo($a);

uDom(document.createElement('cite'))
.text(domain)
.text(targetDomain(ad))
.appendTo($a);

$a.appendTo($li);
Expand Down
94 changes: 54 additions & 40 deletions src/js/adn/vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,62 +223,76 @@
repack();
}

function parseAd(ad, data) {
if (ad.contentType == "img") data.totalImg ++;
else if (ad.contentType == "text") data.totalText ++;
try {
let network = ad.adNetwork ? ad.adNetwork : parseHostname(ad.targetUrl);
// merge common ad system
if (network.indexOf("adssettings.google") > -1 ) {
//ignore adsettings
return data;
} else if(network.indexOf("doubleclick") > -1 || network.indexOf("google") > -1 || ad.pageUrl.indexOf("google.com/search") > -1){
// Merge double click, google ads, google search
network = "google ads";
} else if(network.indexOf("amazon") > -1){
network = "amazon ad system";
} else if(network.indexOf("facebook") > -1){
network = "facebook";
}
addToDict(network, data.adNetworks);
}
catch{
// can't parse
}
try {
const domain = parseDomain(ad.pageUrl);
addToDict(domain, data.sites);
}
catch {
// can't parse
}
return data;
}

function analyze(adsets) {

let data = {
totalImg: 0,
totalText: 0,
sites:{},
adNetworks:{}
adNetworks:{},
};

for (let i = 0, j = adsets && adsets.length; i < j; i++) {
for (const key in adsets[i].children) {
const ad = adsets[i].children[key];
if (ad.contentType == "img") data.totalImg ++;
else if (ad.contentType == "text") data.totalText ++;
try {
let network = ad.adNetwork ? ad.adNetwork : parseHostname(ad.targetUrl);
// merge common ad system
if (network.indexOf("adssettings.google") > -1 ) {
//ignore adsettings
continue;
} else if(network.indexOf("doubleclick") > -1 || network.indexOf("google") > -1 || ad.pageUrl.indexOf("google.com/search") > -1){
// Merge double click, google ads, google search
network = "google ads";
} else if(network.indexOf("amazon") > -1){
network = "amazon ad system";
} else if(network.indexOf("facebook") > -1){
network = "facebook";
}

addToDict(network, data.adNetworks);

}
catch{
// can't parse

}
try {
const domain = parseDomain(ad.pageUrl);
addToDict(domain, data.sites);
}
catch {
// can't parse
//gAds
if (!adsets[i].children) {
const ad = adsets[i];
data = parseAd(ad, data);
} else {
//adsets
for (const key in adsets[i].children) {
const ad = adsets[i].children[key];
data = parseAd(ad, data);
}
}

}

data.sites = sortDict(data.sites);
data.adNetworks = sortDict(data.adNetworks);
data.total = data.totalImg + data.totalText;
//console.log(data);
displayStatistics(data);
}

function displayStatistics(data) {
// clear old data
$('#myStatistics ul').html("");
$('#myStatistics #desc').text("");

if (data.total < gAds.length) {
// partial stats
$('#myStatistics #desc').text("Statistics for " + data.total + "/" + gAds.length + " total ads");
}

// Top Ad Network

Expand Down Expand Up @@ -342,10 +356,9 @@
text: data.totalText
}).appendTo($textAd);

//Toggle
$('.myStatistics-panel').toggle(300);
$('#myStatistics').toggleClass("show");
$('#myStatistics').toggleClass("min");
$('.myStatistics-panel').show(300);
$('#myStatistics').addClass("show");
$('#myStatistics').removeClass("min");

}

Expand Down Expand Up @@ -1852,7 +1865,8 @@
doLayout(runFilter(ext), true)
break;
default:
doLayout(runFilter(bExtent))
doLayout(runFilter(bExtent));
analyze(gAds);
}
// ---------------------------- functions ------------------------------

Expand Down
1 change: 1 addition & 0 deletions src/vault.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
</div>

<div class="myStatistics-panel">
<span id="desc"></span>
<div class="section">
<h4 data-i18n="topAdnetworks"></h4>
<ul id="topAdnetworks">
Expand Down

0 comments on commit 6d025ab

Please sign in to comment.