Skip to content
This repository was archived by the owner on Nov 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions scripts/background.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
class BackgroundWorker {

constructor() {
}

run() {
trektor.browser.runtime.onMessage.addListener(async (msg) => {
trektor.browser.runtime.onMessage.addListener((msg, _, sendResponse) => {
switch (msg.action) {
case "track":
await this.track(...msg.args);
return;
this.track(...msg.args)
.then(() => sendResponse())
.catch((e) => sendResponse(e.message));
break;
case "addTask":
await this.addTask(...msg.args);
return;
this.addTask(...msg.args)
.then(() => sendResponse())
.catch((e) => sendResponse(e.message));
break;
default:
throw new Error(`unknown action: ${msg.action}`);
new Error(`unknown action: ${msg.action}`);
}
return true;
});
}

Expand Down
33 changes: 13 additions & 20 deletions scripts/content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,22 @@ async function addButton() {
trackButton.addEventListener("click", async () => {
trackButtonIcon.classList.add("trektor-state-loading");

try {
await trektor.browser.runtime.sendMessage({
action: "track",
args: [window.location.pathname.split("/", 3)[2]],
});
trackButtonIcon.classList.replace("icon-clock", "icon-check-circle");
window.setTimeout(() => trackButtonIcon.classList.replace("icon-check-circle", "icon-clock"), 2000);
} catch (err) {
window.alert(err);
} finally {
trackButtonIcon.classList.remove("trektor-state-loading");
}
const response = await trektor.browser.runtime.sendMessage({
action: "track",
args: [window.location.pathname.split("/", 3)[2]],
});
trackButtonIcon.classList.replace("icon-clock", "icon-check-circle");
window.setTimeout(() => trackButtonIcon.classList.replace("icon-check-circle", "icon-clock"), 2000);
if (response !== null) window.alert(response);
trackButtonIcon.classList.remove("trektor-state-loading");
});

addButton.addEventListener("click", async () => {
try {
await trektor.browser.runtime.sendMessage({
action: "addTask",
args: [window.location.pathname.split("/", 3)[2]],
});
} catch (err) {
window.alert(err);
}
const response = await trektor.browser.runtime.sendMessage({
action: "addTask",
args: [window.location.pathname.split("/", 3)[2]],
});
if (response !== null) window.alert(response);
});
}

Expand Down