diff --git a/.gitignore b/.gitignore index 1f50f2e..7081bde 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ Archive.zip .amo-upload-uuid dev-resources content copy.js +aula-fixer_v1-2.zip diff --git a/background.js b/background.js new file mode 100644 index 0000000..76560de --- /dev/null +++ b/background.js @@ -0,0 +1,34 @@ +chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { + if (request.type === "GET_KEYWORDS") { + + const remoteUrl = "https://git.wbell.dev/TussockyJoker/Aula-Fixer/raw/branch/main/keywords.txt"; + const localUrl = chrome.runtime.getURL("keywords.txt"); + + // remote + fetch(remoteUrl) + .then(response => { + if (!response.ok) throw new Error("Remote fetch failed"); + return response.text(); + }) + .then(text => { + console.log("Loaded remote keywords"); + sendResponse({ success: true, data: text }); + }) + .catch(() => { + console.warn("Remote failed, loading local fallback"); + + // local + fetch(localUrl) + .then(response => response.text()) + .then(text => { + console.log("Loaded local fallback keywords"); + sendResponse({ success: true, data: text }); + }) + .catch(error => { + sendResponse({ success: false, error: error.toString() }); + }); + }); + + return true; + } +}); \ No newline at end of file diff --git a/content.js b/content.js index 7d5e239..dca64d2 100644 --- a/content.js +++ b/content.js @@ -1,11 +1,13 @@ let keywords = []; -async function loadKeywords() { - try { - const response = await fetch(chrome.runtime.getURL("keywords.txt")); - const text = await response.text(); +function loadKeywords() { + chrome.runtime.sendMessage({ type: "GET_KEYWORDS" }, (response) => { + if (!response || !response.success) { + console.error("Failed to load remote keywords:", response?.error); + return; + } - keywords = text + keywords = response.data .split("\n") .map(k => k.trim().toLowerCase()) .filter(Boolean); @@ -14,10 +16,7 @@ async function loadKeywords() { injectStyles(); startFiltering(); - - } catch (error) { - console.error("Failed to load keywords.txt:", error); - } + }); } function filterNotifications() { @@ -37,13 +36,16 @@ function filterNotifications() { } function injectStyles() { + // Prevent duplicate injection + if (document.getElementById("aula-fixer-styles")) return; + const style = document.createElement("style"); + style.id = "aula-fixer-styles"; style.textContent = ` .css-qbgecn { max-height: 99% !important; padding: 0 !important; - } .css-15ampbt { @@ -64,8 +66,7 @@ function injectStyles() { } .css-nivjaw { - padding: 12px 12px 12px 12px; - + padding: 12px 12px 12px 12px !important; } `; diff --git a/manifest.json b/manifest.json index 648dbe1..181634f 100644 --- a/manifest.json +++ b/manifest.json @@ -1,9 +1,13 @@ { "manifest_version": 3, "name": "Aula Fixer", - "version": "1.2", + "version": "1.3", "description": "Removes all notifications about rooms for rent etc. on Aula and changes styling so that less screen space is wasted.", + "background": { + "service_worker": "background.js" + }, + "content_scripts": [ { "matches": ["https://coventry.aula.education/*"], @@ -11,20 +15,20 @@ } ], + "host_permissions": [ + "https://git.wbell.dev/*" + ], + "web_accessible_resources": [ - { - "resources": ["keywords.txt"], - "matches": ["https://coventry.aula.education/*"] - } + { + "resources": ["keywords.txt"], + "matches": ["https://coventry.aula.education/*"] + } ], "browser_specific_settings": { - "gecko": { - "id": "aula-fixer@tussockyjoker.com", - "data_collection_permissions": { - "required": ["none"], - "optional": [] + "gecko": { + "id": "aula-fixer@tussockyjoker.com" + } } - } -} -} +} \ No newline at end of file