excludes.txt -> keywords.txt

This commit is contained in:
2026-02-21 20:08:30 +00:00
parent 088deb0cb3
commit 9559111ba6
4 changed files with 31 additions and 35 deletions

View File

@@ -1,55 +1,51 @@
let keywords = [];
// Load excludes.txt first
async function loadKeywords() {
try {
const response = await fetch(chrome.runtime.getURL("excludes.txt"));
const text = await response.text();
try {
const response = await fetch(chrome.runtime.getURL("keywords.txt"));
const text = await response.text();
keywords = text
.split("\n")
.map(k => k.trim().toLowerCase())
.filter(Boolean);
keywords = text
.split("\n")
.map(k => k.trim().toLowerCase())
.filter(Boolean);
console.log("Loaded keywords:", keywords);
console.log("Loaded keywords:", keywords);
startFiltering(); // start only after keywords are ready
startFiltering();
} catch (error) {
console.error("Failed to load excludes.txt:", error);
}
} catch (error) {
console.error("Failed to load keywords.txt:", error);
}
}
function filterNotifications() {
const notifications = document.querySelectorAll('div[role="button"]');
const notifications = document.querySelectorAll('div[role="button"]');
notifications.forEach(notification => {
const text = notification.innerText.toLowerCase();
notifications.forEach(notification => {
const text = notification.innerText.toLowerCase();
const containsKeyword = keywords.some(keyword =>
text.includes(keyword)
);
const containsKeyword = keywords.some(keyword =>
text.includes(keyword)
);
if (containsKeyword) {
notification.remove();
}
});
if (containsKeyword) {
notification.remove();
}
});
}
function startFiltering() {
// Run once
filterNotifications();
// Watch for dynamically loaded notifications
const observer = new MutationObserver(() => {
filterNotifications();
});
observer.observe(document.body, {
childList: true,
subtree: true
});
const observer = new MutationObserver(() => {
filterNotifications();
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
// Start everything
loadKeywords();