excludes.txt -> keywords.txt
This commit is contained in:
64
content.js
64
content.js
@@ -1,55 +1,51 @@
|
|||||||
let keywords = [];
|
let keywords = [];
|
||||||
|
|
||||||
// Load excludes.txt first
|
|
||||||
async function loadKeywords() {
|
async function loadKeywords() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(chrome.runtime.getURL("excludes.txt"));
|
const response = await fetch(chrome.runtime.getURL("keywords.txt"));
|
||||||
const text = await response.text();
|
const text = await response.text();
|
||||||
|
|
||||||
keywords = text
|
keywords = text
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.map(k => k.trim().toLowerCase())
|
.map(k => k.trim().toLowerCase())
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
|
||||||
console.log("Loaded keywords:", keywords);
|
console.log("Loaded keywords:", keywords);
|
||||||
|
|
||||||
startFiltering(); // start only after keywords are ready
|
startFiltering();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to load excludes.txt:", error);
|
console.error("Failed to load keywords.txt:", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function filterNotifications() {
|
function filterNotifications() {
|
||||||
const notifications = document.querySelectorAll('div[role="button"]');
|
const notifications = document.querySelectorAll('div[role="button"]');
|
||||||
|
|
||||||
notifications.forEach(notification => {
|
notifications.forEach(notification => {
|
||||||
const text = notification.innerText.toLowerCase();
|
const text = notification.innerText.toLowerCase();
|
||||||
|
|
||||||
const containsKeyword = keywords.some(keyword =>
|
const containsKeyword = keywords.some(keyword =>
|
||||||
text.includes(keyword)
|
text.includes(keyword)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (containsKeyword) {
|
if (containsKeyword) {
|
||||||
notification.remove();
|
notification.remove();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function startFiltering() {
|
function startFiltering() {
|
||||||
// Run once
|
|
||||||
filterNotifications();
|
|
||||||
|
|
||||||
// Watch for dynamically loaded notifications
|
|
||||||
const observer = new MutationObserver(() => {
|
|
||||||
filterNotifications();
|
filterNotifications();
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe(document.body, {
|
const observer = new MutationObserver(() => {
|
||||||
childList: true,
|
filterNotifications();
|
||||||
subtree: true
|
});
|
||||||
});
|
|
||||||
|
observer.observe(document.body, {
|
||||||
|
childList: true,
|
||||||
|
subtree: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start everything
|
|
||||||
loadKeywords();
|
loadKeywords();
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
"web_accessible_resources": [
|
"web_accessible_resources": [
|
||||||
{
|
{
|
||||||
"resources": ["excludes.txt"],
|
"resources": ["keywords.txt"],
|
||||||
"matches": ["https://coventry.aula.education/*"]
|
"matches": ["https://coventry.aula.education/*"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user