Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit danger badge only for SERP tabs & minor perf optimization #1477

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions extension-manifest-v3/src/background/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { order } from '@ghostery/ui/categories';
import DailyStats from '/store/daily-stats.js';
import Options, { observe } from '/store/options.js';

import { shouldShowOperaSerpAlert } from '/notifications/opera-serp.js';
import { shouldSetDangerBadgeForTabId } from '/notifications/opera-serp.js';
import AutoSyncingMap from '/utils/map.js';

import Request from './utils/request.js';
Expand All @@ -38,10 +38,7 @@ function setBadgeColor(color = '#3f4146' /* gray-600 */) {
}

observe('terms', async (terms) => {
if (
!terms ||
(__PLATFORM__ === 'opera' && (await shouldShowOperaSerpAlert()))
) {
if (!terms) {
await chromeAction.setBadgeText({ text: '!' });
setBadgeColor('#f13436' /* danger-500 */);
} else {
Expand All @@ -53,6 +50,12 @@ observe('terms', async (terms) => {
async function refreshIcon(tabId) {
const options = await store.resolve(Options);

if (options.terms && __PLATFORM__ === 'opera') {
shouldSetDangerBadgeForTabId(tabId).then((danger) => {
setBadgeColor(danger ? '#f13436' /* danger-500 */ : undefined);
});
}

const stats = tabStats.get(tabId);
if (!stats) return;

Expand Down
30 changes: 28 additions & 2 deletions extension-manifest-v3/src/notifications/opera-serp.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,34 @@ export async function showOperaSerpNotification(tabId) {
}

export async function shouldShowOperaSerpAlert() {
if (await isSerpSupported()) return false;
const options = await store.resolve(Options);
if (options.onboarding.serpShown < NOTIFICATION_SHOW_LIMIT) {
if (await isSerpSupported()) {
store.set(options, {
onboarding: { serpShown: NOTIFICATION_SHOW_LIMIT },
});
return false;
}

return true;
}

return false;
}

export async function shouldSetDangerBadgeForTabId(tabId) {
const options = await store.resolve(Options);
return options.onboarding.serpShown < NOTIFICATION_SHOW_LIMIT;

if (options.onboarding.serpShown < NOTIFICATION_SHOW_LIMIT) {
try {
await chrome.scripting.insertCSS({
target: { tabId },
css: '',
});

return false;
} catch (e) {
return true;
}
}
}
Loading