This repository was archived by the owner on Nov 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Manifest V3 #17
Merged
Merged
Manifest V3 #17
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d9cc664
merge background script and trektor.js;
wendelin-as 446a5f2
keep background script and trektor.js seperate;
wendelin-as 894fe7b
adress requested changes;
wendelin-as 8cc6a55
trektor nicht als funktion; trektor im content script einbinden
wendelin-as 06243dd
Update manifest.json
wendelin-as 8e6ab8c
import reihenfolge anpassen
wendelin-as File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| class BackgroundWorker { | ||
|
|
||
| constructor() { | ||
| } | ||
|
|
||
| run() { | ||
| trektor.browser.runtime.onMessage.addListener(async (msg) => { | ||
| switch (msg.action) { | ||
| case "track": | ||
| await this.track(...msg.args); | ||
| return; | ||
| case "addTask": | ||
| await this.addTask(...msg.args); | ||
| return; | ||
| default: | ||
| throw new Error(`unknown action: ${msg.action}`); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| async track(cardId) { | ||
| const task = await this.addTask(cardId); | ||
| const card = await trektor.trelloGateway.getCard(cardId); | ||
| const cardName = this.stripStoryPointsAndTaskToken(card.name); | ||
| const response = await trektor.togglGateway.startTimeEntry(task.id, cardName); | ||
| return response.data; | ||
| } | ||
|
|
||
| async addTask(cardId) { | ||
| const card = await trektor.trelloGateway.getCard(cardId); | ||
|
|
||
| const taskPrefixes = card.labels | ||
| .map((label) => label.name.match(/(?<=#)[a-z0-9]+$/)?.[0]) | ||
| .filter((prefix) => prefix !== undefined); | ||
|
|
||
| if (taskPrefixes.length === 0) { | ||
| throw new Error("Card has no valid project labels."); | ||
| } | ||
| if (taskPrefixes.length > 1) { | ||
| throw new Error("Card has multiple project labels."); | ||
| } | ||
| const taskPrefix = taskPrefixes[0]; | ||
|
|
||
| let taskName = card.name.match(/(?<=#)[A-Za-z0-9_-]+/)?.[0]; | ||
|
|
||
| if (taskName === undefined) { | ||
| taskName = `${taskPrefix}_${card.idShort}`; | ||
|
|
||
| await trektor.trelloGateway.updateCard(card.id, { | ||
| name: `${card.name} #${taskName}`, | ||
| }); | ||
| } | ||
|
|
||
| const workspaces = await trektor.togglGateway.getWorkspaces(); | ||
|
|
||
| if (workspaces.length === 0) { | ||
| throw new Error("Could not find any toggl workspaces."); | ||
| } | ||
| if (workspaces.length > 1) { | ||
| throw new Error("Found multiple toggl workspaces. Not sure how to deal with that..."); | ||
| } | ||
| const allProjects = await trektor.togglGateway.getProjects(workspaces[0].id); | ||
| const projects = allProjects.filter((project) => project.name.endsWith(`(${taskPrefix})`)); | ||
|
|
||
| if (projects.length === 0) { | ||
| throw new Error("Could not find any matching toggl project."); | ||
| } | ||
| if (projects.length > 1) { | ||
| throw new Error("Found multiple matching toggl projects. Not sure how to deal with that..."); | ||
| } | ||
| const tasks = await trektor.togglGateway.getTasks(projects[0].id); | ||
| const task = tasks.find((task) => task.name === taskName); | ||
| if (task !== undefined) return task; | ||
|
|
||
| const response = await trektor.togglGateway.createTask(projects[0].id, taskName) | ||
| return response.data; | ||
| } | ||
|
|
||
| stripStoryPointsAndTaskToken(cardName) { | ||
| return cardName | ||
| .replace(/^(\s*\(\d+\))?\s*/, "") // story points, e.g. (3) | ||
| .replace(/\s*#[a-z0-9_]+\s*$/, ""); // task token, e.g. #orga_5417 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| importScripts('background.js', 'trektor.js'); | ||
|
wendelin-as marked this conversation as resolved.
Outdated
|
||
|
|
||
| new BackgroundWorker().run() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| new BackgroundWorker().run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.