Add dynamic privacy policy notification with API fetch

Implements fetching the privacy policy from the BetterSEQTA+ API and displays a notification if the policy has been updated. Adds sanitization for HTML content, updates settings state to track last shown timestamp, and provides a manual trigger in settings. Refactors notification logic for improved security and maintainability.
This commit is contained in:
StroepWafel
2025-11-29 19:47:30 +10:30
parent fd86e57442
commit 2c077bc755
6 changed files with 193 additions and 26 deletions
+32
View File
@@ -2,6 +2,34 @@ import browser from "webextension-polyfill";
import type { SettingsState } from "@/types/storage";
import { fetchNews } from "./background/news";
interface PrivacyPolicyResponse {
last_updated: string;
whatsnew_html: string;
}
async function fetchPrivacyPolicy(sendResponse: (response?: any) => void) {
try {
const response = await fetch("https://betterseqta.org/api/policy/privacy", {
method: "GET",
headers: {
"Accept": "application/json",
},
});
if (!response.ok) {
console.error("[BetterSEQTA+] Failed to fetch privacy policy:", response.status);
sendResponse({ error: `HTTP ${response.status}`, data: null });
return;
}
const data = await response.json() as PrivacyPolicyResponse;
sendResponse({ error: null, data });
} catch (error) {
console.error("[BetterSEQTA+] Error fetching privacy policy:", error);
sendResponse({ error: String(error), data: null });
}
}
function reloadSeqtaPages() {
const result = browser.tabs.query({});
function open(tabs: any) {
@@ -56,6 +84,10 @@ browser.runtime.onMessage.addListener(
fetchNews(request.source ?? "australia", sendResponse);
return true;
case "fetchPrivacyPolicy":
fetchPrivacyPolicy(sendResponse);
return true;
default:
console.log("Unknown request type");
}