Skip to content

Commit 48750bf

Browse files
authored
Merge pull request #2746 from mneunomne/#2740
adjust to badge icon and clicked count on vault button
2 parents 11d1313 + fca35bb commit 48750bf

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

src/css/menu.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ header{
307307
display: block;
308308
background: var(--adn-blue);
309309
height: 20px;
310-
width: 25px;
310+
padding: 0px 5px;
311311
position: absolute;
312312
right: 5px;
313313
top: -10px;

src/js/adn/core.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,6 +2383,7 @@ const adnauseam = (function () {
23832383
const allAds = adlist()
23842384
const json = adsForUI(reqPageStore.rawURL);
23852385
json.total = allAds.length;
2386+
json.clicked = allAds.filter(ad => ad.visitedTs).length;
23862387

23872388
// if we have no page ads, use the most recent (6)
23882389
// avoid sending data for too many ads in messaging

src/js/adn/menu.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ import { broadcast, onBroadcast } from '../broadcast.js';
3939
var updatedButtonState = '';
4040
var colorBlindMode = false
4141

42+
// store values for setCounter
43+
var total = 0
44+
var clicked = 0
45+
4246
// on adnRefresh event, update initialButtonState to updatedButtonState
4347
window.addEventListener('adnRefresh', function (e) {
4448
initialButtonState = updatedButtonState;
@@ -56,7 +60,7 @@ import { broadcast, onBroadcast } from '../broadcast.js';
5660
}, 10)
5761

5862
onBroadcast(request => {
59-
63+
6064
switch (request.what) {
6165

6266
case 'adAttempt':
@@ -95,6 +99,8 @@ import { broadcast, onBroadcast } from '../broadcast.js';
9599
page = json && json.pageUrl;
96100
settings = json && json.prefs;
97101
recent = json && json.recent
102+
total = json && json.total
103+
clicked = json && json.clicked
98104

99105
console.log("[ADN] renderPage settings", settings)
100106

@@ -114,7 +120,7 @@ import { broadcast, onBroadcast } from '../broadcast.js';
114120

115121
if (typeof json !== 'undefined' && json !== null) {
116122
ads = json.data;
117-
setCounts(ads, json.total, json.recent);
123+
setCounts(ads, json.total, json.recent, json.clicked);
118124
} else {
119125
console.warn("[ADN] json null, cant make ad list")
120126
}
@@ -167,11 +173,12 @@ import { broadcast, onBroadcast } from '../broadcast.js';
167173
});
168174
}
169175

170-
const setCounts = function (ads, total, recent) {
171-
const numVisits = recent ? 0 : (visitedCount(ads) || 0);
172-
uDom('#vault-count').text(total || 0);
176+
const setCounts = function (_ads, _total, _recent, _clicked) {
177+
// console.log("[ADN] setCounts", ads, total, recent)
178+
const numVisits = recent ? 0 : (visitedCount(_ads) || 0);
179+
uDom('#vault-count').text(`${_clicked || 0} / ${_total || 0}`);
173180
uDom('#visited').text(i18n$("adnMenuAdsClicked").replace("{{number}}", numVisits || 0));
174-
uDom('#found').text(i18n$("adnMenuAdsDetected").replace("{{count}}", (ads && !recent) ? ads.length : 0));
181+
uDom('#found').text(i18n$("adnMenuAdsDetected").replace("{{count}}", (ads && !_recent) ? _ads.length : 0));
175182
setCost(numVisits);
176183
adjustStatCSS();
177184
}
@@ -212,6 +219,8 @@ import { broadcast, onBroadcast } from '../broadcast.js';
212219
const updateAd = function (ad) { // update class, title, counts
213220
// console.log(ad);
214221
if (verify(ad)) {
222+
clicked += 1
223+
setCounts(ads, total, recent, clicked);
215224

216225
const $ad = updateAdClasses(ad);
217226

src/js/tab.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,15 +1109,16 @@ vAPI.tabs = new vAPI.Tabs();
11091109

11101110
const pageStore = µb.pageStoreFromTabId(tabId);
11111111
let pageDomain = pageStore ? domainFromHostname(pageStore.tabHostname) : null; // ADN;
1112+
1113+
count = adnauseam.currentCount(pageStore.rawURL); // ADN
11121114

11131115
if ( pageStore !== null ) {
11141116
state = pageStore.getNetFilteringSwitch() ? 1 : 0;
11151117
isStrict = pageStore.getIsPageStrictBlocked() ? 1 : 0 // ADN
11161118
if ( state === 1 ) {
11171119
if ( (parts & 0b0010) !== 0 ) {
1118-
const blockCount = pageStore.counts.blocked.any;
1119-
if ( blockCount !== 0 ) {
1120-
badge = µb.formatCount(blockCount);
1120+
if ( count !== 0 ) {
1121+
badge = µb.formatCount(count);
11211122
}
11221123
}
11231124
if ( (parts & 0b0100) !== 0 ) {
@@ -1128,12 +1129,11 @@ vAPI.tabs = new vAPI.Tabs();
11281129
}
11291130

11301131
state = adnauseam.getIconState(state, pageDomain, isClick, isStrict); // ADN
1131-
count = adnauseam.currentCount(pageStore.rawURL); // ADN
11321132
badge = µb.formatCount(count);
11331133
}
11341134

11351135
// https://www.reddit.com/r/uBlockOrigin/comments/d33d37/
1136-
if ( µb.userSettings.showIconBadge === false ) {
1136+
if ( µb.userSettings.showIconBadge === false || count === 0 ) {
11371137
parts |= 0b1000;
11381138
}
11391139

src/menu.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ <h1>
2727
</h1>
2828
<div id="stats">
2929
<div class="wrapper">
30-
<span id="visited" data-i18n="adnMenuAdsClicked">&nbsp;</span>
30+
<span id="visited" data-i18n="adnMenuAdsClicked" alt="Total Ads Clicked / Collected by AdNauseam">&nbsp;</span>
3131
/
3232
<span id="found" data-i18n="adnMenuAdsDetected">&nbsp;</span>
3333
<span id="worth-estimate" class="cost highlighted"></span><a

0 commit comments

Comments
 (0)