From 69c60986ff382f7288df80c8b7557b821806d094 Mon Sep 17 00:00:00 2001 From: Andre Henriques Date: Fri, 4 Oct 2024 12:07:56 +0100 Subject: [PATCH] feat: improved extension and applied list --- .../applications/ApplicationsController.kt | 4 +- extensions/background-script.js | 45 ++++++------------- site/src/routes/AppliyedList.svelte | 10 ++++- 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/api/src/main/kotlin/com/andr3h3nriqu3s/applications/ApplicationsController.kt b/api/src/main/kotlin/com/andr3h3nriqu3s/applications/ApplicationsController.kt index 3a7ab31..f6bf192 100644 --- a/api/src/main/kotlin/com/andr3h3nriqu3s/applications/ApplicationsController.kt +++ b/api/src/main/kotlin/com/andr3h3nriqu3s/applications/ApplicationsController.kt @@ -392,7 +392,7 @@ class ApplicationService( public fun findApplicationByUrl(user: UserDb, url: String, unique_url: String?): Application? { if (unique_url != null) { - val unique = + val unique: List = db.query( "select * from applications where unique_url=? and user_id=?", arrayOf(unique_url, user.id), @@ -405,7 +405,7 @@ class ApplicationService( } } - val applications = + val applications: List = db.query( "select * from applications where url=? and user_id=?", arrayOf(url, user.id), diff --git a/extensions/background-script.js b/extensions/background-script.js index 68919e7..fdb4d92 100644 --- a/extensions/background-script.js +++ b/extensions/background-script.js @@ -31,9 +31,9 @@ browser.runtime.onMessage.addListener(async (message, sender, sendResponse) => { return; } if (message.type === "R_GET_DATA_FROM_PAGE") { - let windowList = (await browser.storage.local.get("windows")).windows ?? []; - if (windowList.length !== 1) return; - const tab = await browser.tabs.get(windowList[0]); + let windowList = (await browser.storage.local.get("windows")).windows; + if (!windowList) return; + const tab = await browser.tabs.get(windowList); browser.tabs.sendMessage(tab.id, { type: "GET_DATA_FROM_PAGE", }); @@ -41,8 +41,8 @@ browser.runtime.onMessage.addListener(async (message, sender, sendResponse) => { } if (message.type !== "MY_GET_URL") return; - let windowList = (await browser.storage.local.get("windows")).windows ?? []; - if (windowList.length !== 1) { + let windowList = (await browser.storage.local.get("windows")).windows; + if (!windowList) { browser.tabs.sendMessage(sender.tab.id, { type: "MY_GET_URL_R", error: "Invalid number of pages marked as target", @@ -51,7 +51,7 @@ browser.runtime.onMessage.addListener(async (message, sender, sendResponse) => { return; } - const tab = await browser.tabs.get(windowList[0]); + const tab = await browser.tabs.get(windowList); browser.tabs.sendMessage(tab.id, { type: "GET_DATA_FROM_PAGE", @@ -66,45 +66,26 @@ browser.runtime.onMessage.addListener(async (message, sender, sendResponse) => { async function startup() { await browser.storage.local.set({ - windows: [], + windows: null, interesetWindows: [], }); - // Clear the menus from the prev install + // Clear the menus from the prev install / startup browser.menus.removeAll(); browser.menus.create({ id: "mark-page", - title: "Mark Page As the Glassdoor target", - contexts: ["all"], - }); - - browser.menus.create({ - id: "mark-page-clear", - title: "Clear Marked Pages", + title: "Mark Page As the Url target", contexts: ["all"], }); browser.menus.onClicked.addListener(async function (e, tab) { - let windowList = - (await browser.storage.local.get("windows")).windows ?? []; - - console.log("test", e.menuItemId, e.menuItemId === "mark-page-clear"); - if (e.menuItemId === "mark-page") { - console.log("marking page", tab); - if (windowList.includes(tab.id)) { - windowList = windowList.filter((a) => a !== tab.id); - } else { - windowList.push(tab.id); - } - } else if (e.menuItemId === "mark-page-clear") { - windowList = []; - console.log("clear"); + await browser.storage.local.set({ + windows: tab.id, + }); } - await browser.storage.local.set({ - windows: windowList, - }); }); } browser.runtime.onInstalled.addListener(startup); +browser.runtime.onStartup.addListener(startup); diff --git a/site/src/routes/AppliyedList.svelte b/site/src/routes/AppliyedList.svelte index 38307d9..8f234fe 100644 --- a/site/src/routes/AppliyedList.svelte +++ b/site/src/routes/AppliyedList.svelte @@ -25,8 +25,16 @@

{item.title} + {#if item.company} +
+ @ {item.company} +
+ {/if}

- + {item.url}