Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat(chrome-ext): button to clear ignored lints (#4829)

Elijah Potter42c2b337be68
diff --git a/packages/chrome-plugin/src/ProtocolClient.ts b/packages/chrome-plugin/src/ProtocolClient.ts
index 1a44df82f..b0b5adcb7 100644
--- a/packages/chrome-plugin/src/ProtocolClient.ts
+++ b/packages/chrome-plugin/src/ProtocolClient.ts
@@ -168,6 +168,14 @@ export default class ProtocolClient {
await chrome.runtime.sendMessage({ kind: 'setReviewed', reviewed });
}
+ /** Clear and persist ignored suggestions for all websites. Open pages may need a reload. */
+ public static async clearIgnoredLints(): Promise<void> {
+ const response = await chrome.runtime.sendMessage({ kind: 'clearIgnoredLints' });
+ if (response?.kind !== 'clearIgnoredLints' || !response.success) {
+ throw new Error('Could not clear ignored suggestions. Please try again.');
+ }
+ }
+
public static async ignoreHash(hash: string): Promise<void> {
await chrome.runtime.sendMessage({ kind: 'ignoreLint', contextHash: hash });
this.lintCache.clear();
diff --git a/packages/chrome-plugin/src/background/index.ts b/packages/chrome-plugin/src/background/index.ts
index 5084934de..3f0161501 100644
--- a/packages/chrome-plugin/src/background/index.ts
+++ b/packages/chrome-plugin/src/background/index.ts
@@ -11,6 +11,7 @@ import {
ActivationKey,
type AddToUserDictionaryRequest,
type AddWeirpackRequest,
+ type ClearIgnoredLintsResponse,
createUnitResponse,
type GetActivationKeyResponse,
type GetConfigRequest,
@@ -251,6 +252,8 @@ function handleRequest(message: Request, sender?: chrome.runtime.MessageSender):
return handleSetDomainStatus(message);
case 'addToUserDictionary':
return handleAddToUserDictionary(message);
+ case 'clearIgnoredLints':
+ return handleClearIgnoredLints();
case 'ignoreLint':
return handleIgnoreLint(message);
case 'setDefaultStatus':
@@ -424,6 +427,19 @@ async function handleSetDelay(req: SetDelayRequest): Promise<UnitResponse> {
return createUnitResponse();
}
+/** Reset ignored suggestions globally and acknowledge only after the reset is saved. */
+async function handleClearIgnoredLints(): Promise<ClearIgnoredLintsResponse> {
+ try {
+ await ensureLinterReady();
+ await linter.clearIgnoredLints();
+ await setIgnoredLints(await linter.exportIgnoredLints());
+ return { kind: 'clearIgnoredLints', success: true };
+ } catch (error) {
+ console.error('Failed to clear ignored suggestions:', error);
+ return { kind: 'clearIgnoredLints', success: false };
+ }
+}
+
async function handleIgnoreLint(req: IgnoreLintRequest): Promise<UnitResponse> {
await ensureLinterReady();
await linter.ignoreLintHash(BigInt(req.contextHash));
@@ -668,7 +684,7 @@ async function getLintConfig(): Promise<LintConfig> {
return JSON.parse(resp.lintConfig);
}
-/** Get the ignored lint state from permanent storage. */
+/** Update the linter's ignored suggestions and save them to permanent storage. */
async function setIgnoredLints(state: string): Promise<void> {
await linter.importIgnoredLints(state);
linterHasPersistedState = true;
diff --git a/packages/chrome-plugin/src/options/Options.svelte b/packages/chrome-plugin/src/options/Options.svelte
index 4a26f8f76..78970c1a5 100644
--- a/packages/chrome-plugin/src/options/Options.svelte
+++ b/packages/chrome-plugin/src/options/Options.svelte
@@ -14,6 +14,30 @@ import { ActivationKey } from '../protocol';
import StructuredRuleSettings from './StructuredRuleSettings.svelte';
let loaded = $state(false);
+let clearingIgnoredSuggestions = $state(false);
+let ignoredSuggestionsStatus = $state('');
+
+/** Confirm a global reset and report completion or failure without changing other settings. */
+async function clearIgnoredSuggestions(): Promise<void> {
+ if (
+ !window.confirm(
+ 'Clear ignored suggestions across all websites? Custom dictionary words and disabled rules will not change.',
+ )
+ ) {
+ return;
+ }
+ clearingIgnoredSuggestions = true;
+ ignoredSuggestionsStatus = '';
+ try {
+ await ProtocolClient.clearIgnoredLints();
+ ignoredSuggestionsStatus =
+ 'Ignored suggestions cleared. Reload open pages to show suggestions again.';
+ } catch {
+ ignoredSuggestionsStatus = 'Could not clear ignored suggestions. Please try again.';
+ } finally {
+ clearingIgnoredSuggestions = false;
+ }
+}
let lintConfig: LintConfig = $state({});
let structuredLintConfig: StructuredLintConfig = $state({ settings: [] });
@@ -638,6 +662,22 @@ async function removeWeirpack(id: string) {
</div>
</div>
+ <div class="flex flex-col gap-2 py-3.5">
+ <h3 class="text-base font-semibold">Ignored suggestions</h3>
+ <p id="ignored-suggestions-desc" class="text-xs text-gray-600 dark:text-[#d1d5db]!">
+ Clear ignored suggestions across all websites. Custom dictionary words and disabled rules will not change.
+ </p>
+ <Button
+ size="sm"
+ disabled={clearingIgnoredSuggestions}
+ aria-describedby="ignored-suggestions-desc"
+ on:click={clearIgnoredSuggestions}
+ >
+ {clearingIgnoredSuggestions ? 'Clearing…' : 'Clear ignored suggestions'}
+ </Button>
+ <p role="status" class="text-xs">{ignoredSuggestionsStatus}</p>
+ </div>
+
<!-- User Dictionary -->
<div class="flex flex-col gap-2 py-3.5">
<div>
diff --git a/packages/chrome-plugin/src/protocol.ts b/packages/chrome-plugin/src/protocol.ts
index d11595931..17d2dee27 100644
--- a/packages/chrome-plugin/src/protocol.ts
+++ b/packages/chrome-plugin/src/protocol.ts
@@ -21,6 +21,7 @@ export type Request =
| AddToUserDictionaryRequest
| SetUserDictionaryRequest
| IgnoreLintRequest
+ | ClearIgnoredLintsRequest
| GetUserDictionaryRequest
| GetActivationKeyRequest
| SetActivationKeyRequest
@@ -41,6 +42,7 @@ export type Response =
| GetConfigResponse
| GetStructuredConfigResponse
| UnitResponse
+ | ClearIgnoredLintsResponse
| GetLintDescriptionsResponse
| GetDialectResponse
| GetIsolateEnglishResponse
@@ -226,6 +228,16 @@ export type SetReviewedRequest = {
reviewed: boolean;
};
+/** Clear ignored suggestions across all websites without changing other settings. */
+export type ClearIgnoredLintsRequest = {
+ kind: 'clearIgnoredLints';
+};
+
+export type ClearIgnoredLintsResponse = {
+ kind: 'clearIgnoredLints';
+ success: boolean;
+};
+
export type IgnoreLintRequest = {
kind: 'ignoreLint';
contextHash: string;
diff --git a/packages/web/static/images/chrome_extension_options.png b/packages/web/static/images/chrome_extension_options.png
index e0c600c41..d6f9e87ce 100644
Binary files a/packages/web/static/images/chrome_extension_options.png and b/packages/web/static/images/chrome_extension_options.png differ