diff --git a/extensions/background-script.js b/extensions/background-script.js index bd780cd..3376100 100644 --- a/extensions/background-script.js +++ b/extensions/background-script.js @@ -3,6 +3,33 @@ });*/ browser.runtime.onMessage.addListener(async (message, sender, sendResponse) => { + if (message.type === "REGISTER_INTEREST") { + let interestList = + (await browser.storage.local.get("interesetWindows")) + .interesetWindows ?? []; + // Already has interest! + if (interestList.includes(sender.tab.id)) { + return; + } + interestList.push(sender.tab.id); + + await browser.storage.local.set({ + interesetWindows: interestList, + }); + + return; + } + if (message.type === "GOT_INFO_R") { + // TODO then send this information back to that page + let interestList = + (await browser.storage.local.get("interesetWindows")) + .interesetWindows ?? []; + + interestList.forEach((a) => { + browser.tabs.sendMessage(a, message); + }); + return; + } if (message.type !== "MY_GET_URL") return; let windowList = (await browser.storage.local.get("windows")).windows ?? []; @@ -28,11 +55,10 @@ browser.runtime.onMessage.addListener(async (message, sender, sendResponse) => { }); }); -browser.runtime.onInstalled.addListener(async () => { - console.log(browser); - +async function startup() { await browser.storage.local.set({ windows: [], + interesetWindows: [], }); // Clear the menus from the prev install @@ -70,4 +96,6 @@ browser.runtime.onInstalled.addListener(async () => { windows: windowList, }); }); -}); +} + +browser.runtime.onInstalled.addListener(startup); diff --git a/extensions/definitions.js b/extensions/definitions.js index f2b1d04..adb5589 100644 --- a/extensions/definitions.js +++ b/extensions/definitions.js @@ -1,6 +1,16 @@ browser.runtime.onMessage.addListener(function (message) { if (message.type === "MY_GET_URL_R") { window.postMessage(message); + } else if (message.type === "GET_DATA_FROM_PAGE") { + let company = document + .querySelector('header[data-test="job-details-header"]') + .children[0].children[0].querySelector("h4").innerHTML; + let jobTitle = document + .querySelector('header[data-test="job-details-header"]') + .querySelector("h1").innerHTML; + browser.runtime.sendMessage({ type: "GOT_INFO_R", company, jobTitle }); + } else if (message.type === "GOT_INFO_R") { + window.postMessage(message); } }); @@ -10,10 +20,7 @@ window.addEventListener("message", function (e) { } else if (e.data.type === "HAS_EXTENSION_Q") { console.log("Got request for ext"); window.postMessage({ type: "HAS_EXTENSION" }); - } else if (e.data.type === "GET_DATA_FROM_PAGE") { - console.log( - document.querySelector('header[data-test="job-details-header"]'), - ); + } else if (e.data.type === "REGISTER_INTEREST") { + browser.runtime.sendMessage({ type: "REGISTER_INTEREST" }); } - //console.log("here2", e); }); diff --git a/site/src/routes/cv/+page.svelte b/site/src/routes/cv/+page.svelte index f2fb31a..75e50f6 100644 --- a/site/src/routes/cv/+page.svelte +++ b/site/src/routes/cv/+page.svelte @@ -22,30 +22,38 @@