Skip to content

Commit 210ae12

Browse files
committed
Simplify TrackerException fields
1 parent b0116ee commit 210ae12

19 files changed

+412
-381
lines changed

extension-manifest-v3/src/background/adblocker.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,7 @@ if (__PLATFORM__ === 'firefox') {
352352
if (details.type !== 'main_frame') {
353353
updateTabStats(details.tabId, [request]);
354354

355-
const isTrusted = request.metadata?.isTrusted;
356-
357-
if (isTrusted) {
355+
if (request.metadata?.isTrusted) {
358356
return;
359357
}
360358
}

extension-manifest-v3/src/background/exceptions.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ async function convertExceptionsToFilters(exceptions) {
6464
};
6565

6666
const blockedByDefault = isCategoryBlockedByDefault(pattern.category);
67-
const shouldBlock =
68-
blockedByDefault !== (exception?.overwriteStatus || false);
6967

70-
let blockFilters = pattern.filters.map((filter) => parseFilter(filter));
68+
const blockFilters = pattern.filters.map((filter) => parseFilter(filter));
7169

7270
if (blockedByDefault) {
7371
blockFilters.push(
@@ -79,18 +77,19 @@ async function convertExceptionsToFilters(exceptions) {
7977

8078
const allowFilters = blockFilters.map((filter) => negateFilter(filter));
8179

82-
if (exception.overwriteStatus) {
83-
filters.push(...(shouldBlock ? blockFilters : allowFilters));
80+
// Exception overwrites default behavior
81+
if (exception.blocked !== blockedByDefault) {
82+
filters.push(...(exception.blocked ? blockFilters : allowFilters));
8483
}
8584

86-
if (shouldBlock) {
87-
for (const domain of exception.allowed) {
85+
if (exception.blocked) {
86+
for (const domain of exception.trustedDomains) {
8887
for (const filter of allowFilters) {
8988
filters.push(restrictFilter(filter, domain));
9089
}
9190
}
9291
} else {
93-
for (const domain of exception.blocked) {
92+
for (const domain of exception.blockedDomains) {
9493
for (const filter of blockFilters) {
9594
filters.push(restrictFilter(filter, domain));
9695
}

extension-manifest-v3/src/pages/panel/views/home.js

+6-24
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@
1111

1212
import { html, store, router } from 'hybrids';
1313

14+
import { openTabWithUrl } from '/utils/tabs.js';
15+
1416
import Options from '/store/options.js';
1517
import TabStats from '/store/tab-stats.js';
16-
import TrackerException, {
17-
getExceptionStatus,
18-
} from '/store/tracker-exception.js';
19-
import Notification from '../store/notification.js';
2018

21-
import { openTabWithUrl } from '/utils/tabs.js';
22-
import { isCategoryBlockedByDefault } from '../../../utils/trackerdb.js';
19+
import Notification from '../store/notification.js';
2320

2421
import sleep from '../assets/sleep.svg';
2522

@@ -80,27 +77,11 @@ export default {
8077
[router.connect]: { stack: [Navigation, TrackerDetails, ProtectionStatus] },
8178
options: store(Options),
8279
stats: store(TabStats),
83-
trackerExceptions: store([TrackerException]),
84-
trackers: ({ stats, trackerExceptions, paused }) => {
85-
if (!store.ready(stats, trackerExceptions)) return null;
86-
if (paused) return stats.trackers;
87-
88-
return stats.trackers.map((t) => {
89-
const exception = trackerExceptions.find((e) => e.id === t.id);
90-
return {
91-
...t,
92-
status: (exception &&
93-
getExceptionStatus(exception, stats.domain, t.category)) || {
94-
type: isCategoryBlockedByDefault(t.category) ? 'block' : 'trust',
95-
},
96-
};
97-
});
98-
},
9980
notification: store(Notification),
10081
paused: ({ options, stats }) =>
10182
store.ready(options, stats) &&
10283
options.paused.find(({ id }) => id === stats.domain),
103-
content: ({ options, stats, trackers, notification, paused }) => html`
84+
content: ({ options, stats, notification, paused }) => html`
10485
<template layout="column grow relative height::488px">
10586
${store.ready(options, stats) &&
10687
html`
@@ -152,7 +133,8 @@ export default {
152133
<ui-panel-stats
153134
domain="${stats.domain}"
154135
categories="${stats.topCategories}"
155-
trackers="${trackers}"
136+
trackers="${stats.trackers}"
137+
paused="${paused}"
156138
dialog="${TrackerDetails}"
157139
exceptionDialog="${ProtectionStatus}"
158140
type="${options.panel.statsType}"

extension-manifest-v3/src/pages/panel/views/protection-status.js

+32-45
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,15 @@ import { html, msg, router, store } from 'hybrids';
22

33
import * as labels from '@ghostery/ui/labels';
44

5-
import { isCategoryBlockedByDefault } from '../../../utils/trackerdb.js';
6-
75
import TabStats from '/store/tab-stats.js';
8-
import TrackerException from '/store/tracker-exception.js';
9-
10-
function toggleException(type) {
11-
return ({ exception, stats }) => {
12-
const list = [...exception[type]];
13-
const index = list.indexOf(stats.domain);
14-
if (index !== -1) {
15-
list.splice(index, 1);
16-
} else {
17-
list.push(stats.domain);
18-
}
6+
import { toggleExceptionDomain } from '/store/tracker-exception.js';
197

20-
store.set(exception, { [type]: list });
21-
};
8+
function toggleDomain({ stats, tracker }) {
9+
toggleExceptionDomain(
10+
tracker.exception,
11+
stats.domain,
12+
tracker.blockedByDefault,
13+
);
2214
}
2315

2416
export default {
@@ -27,21 +19,17 @@ export default {
2719
trackerId: '',
2820
tracker: ({ stats, trackerId }) =>
2921
stats.trackers.find((t) => t.id === trackerId),
30-
exception: store(TrackerException, { id: 'trackerId' }),
31-
blockedByDefault: ({ tracker }) =>
32-
isCategoryBlockedByDefault(tracker.category),
33-
blockedOnSite: ({ stats, exception }) =>
34-
store.ready(exception) && exception.blocked.includes(stats.domain),
35-
allowedOnSite: ({ stats, exception }) =>
36-
store.ready(exception) && exception.allowed.includes(stats.domain),
37-
content: ({
38-
stats,
39-
tracker,
40-
exception,
41-
blockedByDefault,
42-
blockedOnSite,
43-
allowedOnSite,
44-
}) => html`
22+
blocked: ({ tracker }) =>
23+
store.ready(tracker.exception)
24+
? tracker.exception.blocked
25+
: tracker.blockedByDefault,
26+
blockedOnSite: ({ stats, tracker }) =>
27+
store.ready(tracker.exception) &&
28+
tracker.exception.blockedDomains.includes(stats.domain),
29+
allowedOnSite: ({ stats, tracker }) =>
30+
store.ready(tracker.exception) &&
31+
tracker.exception.trustedDomains.includes(stats.domain),
32+
content: ({ stats, tracker, blocked, blockedOnSite, allowedOnSite }) => html`
4533
<template layout="column">
4634
<gh-panel-dialog>
4735
<div
@@ -56,7 +44,7 @@ export default {
5644
tracker.company + ' •'}
5745
${labels.categories[tracker.category]}
5846
</ui-text>
59-
${store.ready(exception) &&
47+
${(store.ready(tracker.exception) || store.error(tracker.exception)) &&
6048
html`
6149
<div layout="column gap:3">
6250
<div layout="column gap">
@@ -68,16 +56,15 @@ export default {
6856
</div>
6957
<ui-panel-protection-status-toggle
7058
layout="self:center"
71-
value="${exception.overwriteStatus}"
72-
blockByDefault="${blockedByDefault}"
59+
value="${blocked}"
7360
tooltip
74-
onchange="${html.set(exception, 'overwriteStatus')}"
61+
onchange="${html.set(tracker.exception, 'blocked')}"
7562
></ui-panel-protection-status-toggle>
7663
</div>
7764
<gh-panel-card type="info">
7865
<ui-text type="label-s" color="primary-700" layout="row gap:0.5">
7966
<ui-icon name="info-filled"></ui-icon>
80-
${blockedByDefault
67+
${tracker.blockedByDefault
8168
? msg`Our recommendation for this activity: Blocked`
8269
: msg`Our recommendation for this activity: Trusted`}
8370
</ui-text>
@@ -88,27 +75,27 @@ export default {
8875
Add ${stats.domain} as exception
8976
</ui-text>
9077
<ui-text type="body-s" color="gray-500">
91-
${blockedByDefault === exception.overwriteStatus
92-
? msg`Block on this website`
93-
: msg`Trust on this website`}
78+
${blocked
79+
? msg`Trust on this website`
80+
: msg`Block on this website`}
9481
</ui-text>
9582
</div>
96-
${blockedByDefault === exception.overwriteStatus
83+
${blocked
9784
? html`
9885
<ui-toggle
99-
value="${blockedOnSite}"
100-
onchange="${toggleException('blocked')}"
86+
value="${allowedOnSite}"
87+
onchange="${toggleDomain}"
10188
type="status"
102-
color="danger-500"
89+
color="success-500"
10390
layout="margin:top:0.5"
10491
></ui-toggle>
10592
`
10693
: html`
10794
<ui-toggle
108-
value="${allowedOnSite}"
109-
onchange="${toggleException('allowed')}"
95+
value="${blockedOnSite}"
96+
onchange="${toggleDomain}"
11097
type="status"
111-
color="success-500"
98+
color="danger-500"
11299
layout="margin:top:0.5"
113100
></ui-toggle>
114101
`}

0 commit comments

Comments
 (0)