feat: improved extension and applied list

This commit is contained in:
Andre Henriques 2024-10-04 12:07:56 +01:00
parent 4b4eb1ab02
commit 69c60986ff
3 changed files with 24 additions and 35 deletions

View File

@ -392,7 +392,7 @@ class ApplicationService(
public fun findApplicationByUrl(user: UserDb, url: String, unique_url: String?): Application? { public fun findApplicationByUrl(user: UserDb, url: String, unique_url: String?): Application? {
if (unique_url != null) { if (unique_url != null) {
val unique = val unique: List<Application> =
db.query( db.query(
"select * from applications where unique_url=? and user_id=?", "select * from applications where unique_url=? and user_id=?",
arrayOf(unique_url, user.id), arrayOf(unique_url, user.id),
@ -405,7 +405,7 @@ class ApplicationService(
} }
} }
val applications = val applications: List<Application> =
db.query( db.query(
"select * from applications where url=? and user_id=?", "select * from applications where url=? and user_id=?",
arrayOf(url, user.id), arrayOf(url, user.id),

View File

@ -31,9 +31,9 @@ browser.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
return; return;
} }
if (message.type === "R_GET_DATA_FROM_PAGE") { if (message.type === "R_GET_DATA_FROM_PAGE") {
let windowList = (await browser.storage.local.get("windows")).windows ?? []; let windowList = (await browser.storage.local.get("windows")).windows;
if (windowList.length !== 1) return; if (!windowList) return;
const tab = await browser.tabs.get(windowList[0]); const tab = await browser.tabs.get(windowList);
browser.tabs.sendMessage(tab.id, { browser.tabs.sendMessage(tab.id, {
type: "GET_DATA_FROM_PAGE", type: "GET_DATA_FROM_PAGE",
}); });
@ -41,8 +41,8 @@ browser.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
} }
if (message.type !== "MY_GET_URL") return; if (message.type !== "MY_GET_URL") return;
let windowList = (await browser.storage.local.get("windows")).windows ?? []; let windowList = (await browser.storage.local.get("windows")).windows;
if (windowList.length !== 1) { if (!windowList) {
browser.tabs.sendMessage(sender.tab.id, { browser.tabs.sendMessage(sender.tab.id, {
type: "MY_GET_URL_R", type: "MY_GET_URL_R",
error: "Invalid number of pages marked as target", error: "Invalid number of pages marked as target",
@ -51,7 +51,7 @@ browser.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
return; return;
} }
const tab = await browser.tabs.get(windowList[0]); const tab = await browser.tabs.get(windowList);
browser.tabs.sendMessage(tab.id, { browser.tabs.sendMessage(tab.id, {
type: "GET_DATA_FROM_PAGE", type: "GET_DATA_FROM_PAGE",
@ -66,45 +66,26 @@ browser.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
async function startup() { async function startup() {
await browser.storage.local.set({ await browser.storage.local.set({
windows: [], windows: null,
interesetWindows: [], interesetWindows: [],
}); });
// Clear the menus from the prev install // Clear the menus from the prev install / startup
browser.menus.removeAll(); browser.menus.removeAll();
browser.menus.create({ browser.menus.create({
id: "mark-page", id: "mark-page",
title: "Mark Page As the Glassdoor target", title: "Mark Page As the Url target",
contexts: ["all"],
});
browser.menus.create({
id: "mark-page-clear",
title: "Clear Marked Pages",
contexts: ["all"], contexts: ["all"],
}); });
browser.menus.onClicked.addListener(async function (e, tab) { 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") { if (e.menuItemId === "mark-page") {
console.log("marking page", tab); await browser.storage.local.set({
if (windowList.includes(tab.id)) { windows: 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: windowList,
});
}); });
} }
browser.runtime.onInstalled.addListener(startup); browser.runtime.onInstalled.addListener(startup);
browser.runtime.onStartup.addListener(startup);

View File

@ -25,8 +25,16 @@
<div class:animate-pulse={applicationStore.dragging?.id === item.id}> <div class:animate-pulse={applicationStore.dragging?.id === item.id}>
<h2 class="text-lg text-blue-500"> <h2 class="text-lg text-blue-500">
{item.title} {item.title}
{#if item.company}
<div class="text-violet-800">
@ {item.company}
</div>
{/if}
</h2> </h2>
<a href={item.url} class="text-violet-600 overflow-hidden whitespace-nowrap block"> <a
href={item.url}
class="text-violet-600 overflow-hidden whitespace-nowrap block"
>
{item.url} {item.url}
</a> </a>
</div> </div>