applications-tracker/extensions/definitions.js

35 lines
1.3 KiB
JavaScript

browser.runtime.onMessage.addListener((message) => {
if (message.type === "MY_GET_URL_R") {
window.postMessage(message);
} else if (message.type === "GET_DATA_FROM_PAGE") {
const company = document
.querySelector('header[data-test="job-details-header"]')
.children[0].children[0].querySelector("h4").innerHTML;
const jobTitle = document
.querySelector('header[data-test="job-details-header"]')
.querySelector("h1").innerHTML;
let money = ""
const moneySectionNode = document.querySelector('section>section');
if (moneySectionNode && ["Base pay range", "Base pay"].includes(moneySectionNode.querySelector('h2').textContent)) {
money = moneySectionNode.querySelector("div>div>div").children[1]?.textContent ?? ''
}
browser.runtime.sendMessage({ type: "GOT_INFO_R", company, jobTitle, money });
} else if (message.type === "GOT_INFO_R") {
window.postMessage(message);
}
});
window.addEventListener("message", (e) => {
if (e.data.type === "MY_GET_URL") {
browser.runtime.sendMessage({ type: "MY_GET_URL" });
} else if (e.data.type === "HAS_EXTENSION_Q") {
console.log("Got request for ext");
window.postMessage({ type: "HAS_EXTENSION" });
} else if (e.data.type === "REGISTER_INTEREST") {
browser.runtime.sendMessage({ type: "REGISTER_INTEREST" });
}
});