Skip to content
This repository was archived by the owner on Nov 11, 2025. It is now read-only.
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
8 changes: 8 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
env:
browser: true
es2021: true
extends:
- airbnb-base
parserOptions:
ecmaVersion: latest
rules: {}
12 changes: 0 additions & 12 deletions background.js

This file was deleted.

264 changes: 122 additions & 142 deletions content_script.js
Original file line number Diff line number Diff line change
@@ -1,146 +1,126 @@
function addButton() {
const sidebar = document.querySelector(".window-sidebar")
const button = document.createElement('span');
button.classList.add('button-link');
button.addEventListener('click', onClick);
sidebar.prepend(button);

const buttonIcon = document.createElement('span');
buttonIcon.classList.add('icon-sm', 'plugin-icon');
buttonIcon.innerText = '+';
button.append(buttonIcon);

const buttonText = document.createElement('span');
buttonText.innerText = 'Toggl Task';
button.append(buttonText);

sidebar.querySelector(".mod-no-top-margin").classList.remove("mod-no-top-margin")
sidebar.querySelector(".js-sidebar-add-heading").classList.remove("mod-no-top-margin")
/* eslint-disable no-undef */
/* eslint-disable no-alert */

async function onClick() {
const trelloApiKey = 'afadffe77f745496f80ebb4bf460c615';
const tokens = await trektor.storage.get(['trello', 'toggl']);

const idLong = window.location.pathname.split('/')[2];
let url = new URL(`https://api.trello.com/1/cards/${idLong}`);
const cardInfo = await trektor.fetchJSON(url, {
headers: {
Authorization: `OAuth oauth_consumer_key="${trelloApiKey}", oauth_token="${tokens.trello}"`,
'Content-Type': 'application/json',
},
});

if (cardInfo === false) {
return false;
}

const {
idShort,
} = cardInfo;
const labels = cardInfo.labels.filter((label) => label.name.includes('#'));
if (labels.length > 1) {
alert(`Diese Karte besitzt sowohl das Label ${labels[0].name} als auch das Label ${labels[1].name}`);
return false;
}
if (labels.length === 0) {
alert('Diese Karte besitzt kein unterstütztes Projekt Label.');
return false;
}
const labelShort = labels[0].name.split('#').pop();

if (!cardInfo.name.endsWith(`#${labelShort}_${idShort}`)) {
url = new URL(`https://api.trello.com/1/cards/${idLong}`);

const data = {
name: `${cardInfo.name} #${labelShort}_${idShort}`,
};
trektor.fetchJSON(url, {
method: 'PUT',
headers: {
Authorization: `OAuth oauth_consumer_key="${trelloApiKey}", oauth_token="${tokens.trello}"`,
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
}

url = new URL('https://api.track.toggl.com/api/v8/workspaces');
const togglAuth = btoa(`${tokens.toggl}:api_token`);
const workspaces = await trektor.fetchJSON(url, {
headers: {
Authorization: `Basic ${togglAuth}`,
'Content-Type': 'application/json',
},
});
if (workspaces === false) {
return false;
}
const workspace = workspaces[0];

url = new URL(`https://api.track.toggl.com/api/v8/workspaces/${workspace.id}/projects`);
const projects = await trektor.fetchJSON(url, {
headers: {
Authorization: `Basic ${togglAuth}`,
'Content-Type': 'application/json',
},
});
if (projects === false) {
return false;
}
const matchingProjects = projects.filter((project) => project.name.endsWith(`(${labelShort})`));
if (matchingProjects.length === 0) {
alert('Kein passendes Toggl-Projekt gefunden.');
return false;
}
if (matchingProjects.length > 1) {
alert(`Mehrere Toggl-Projekte, die mit "(${labelShort})" enden gefunden (${matchingProjects[0].name} und ${matchingProjects[1].name})`);
return false;
}
const project = matchingProjects[0];
url = new URL('https://api.track.toggl.com/api/v8/tasks');
const data = {
task: {
name: `${labelShort}_${idShort}`,
pid: project.id,
},
};
const response = trektor.fetchJSON(url, {
method: 'POST',
headers: {
Authorization: `Basic ${togglAuth}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
}, `Toggl task ${labelShort}_${idShort} existiert bereits.`);
return !!(response);
}

const mappings = {
"GG": "gg",
"Audience Builder": "ab",
"Audience Exporter": "ae",
"Cta Calls": "xcta",
"Camper": "camper",
"Praktikum #pr": "pr"
};

function onClick() {
let trelloApiKey = "afadffe77f745496f80ebb4bf460c615"
trektor.storage.get(['trello', 'toggl']).then(result => {
const trelloToken = result.trello
const togglToken = result.toggl

const idLong = window.location.pathname.split("/")[2];
var url = new URL(`https://api.trello.com/1/cards/${idLong}`)
fetch(url.toString(), {
headers: {
'Authorization': `OAuth oauth_consumer_key="${trelloApiKey}", oauth_token="${trelloToken}"`,
'Content-Type': 'application/json'
},
}).then(response => response.json()).then(response => {
const idShort = response["idShort"]

var labelShort, labelLong = undefined
for (var i in response["labels"]) {
if (labelShort == undefined) {
labelShort = mappings[response["labels"][i]["name"]]
labelLong = (labelShort != undefined) ? response["labels"][i]["name"] : labelLong
} else if (mappings[response["labels"][i]["name"]] != undefined) {
alert(`Diese Karte hat sowohl "${labelShort}" als auch "${mappings[response["labels"][i]["name"]]}".`)
}
}

if (labelShort == undefined) {
alert("Diese Karte besitzt kein unterstütztes Projekt Label.")
return false
}

if (!response["name"].endsWith(`#${labelShort}_${idShort}`)) {


url = new URL(`https://api.trello.com/1/cards/${idLong}`)

var data = {
"name": `${response["name"]} #${labelShort}_${idShort}`
};
fetch(url.toString(), {
method: 'PUT',
headers: {
'Authorization': `OAuth oauth_consumer_key="${trelloApiKey}", oauth_token="${trelloToken}"`,
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then(response => {
if (!response.ok) {
alert(`Error ${response.status}:\n${response.statusText}`)
return false
}

})


}

url = new URL("https://api.track.toggl.com/api/v8/workspaces")
const togglAuth = btoa(`${togglToken}:api_token`)
trektor.fetchJSON(url.toString(), {
headers: {
'Authorization': `Basic ${togglAuth}`,
'Content-Type': 'application/json'
}
}).then(response => {
for (var i in response) {
if (response[i]["name"] == "aboutsource") {
var wid = response[i]["id"]
}
}
if (wid == undefined) {
alert("WorkspaceID undefined\nDies bedeutet, du hast entweder keinen Zugriff zum a:s toggl oder es ist kein API-Token angegeben.")
return false
}

url = new URL(`https://api.track.toggl.com/api/v8/workspaces/${wid}/projects`)
trektor.fetchJSON(url.toString(), {
headers: {
'Authorization': `Basic ${togglAuth}`,
'Content-Type': 'application/json'
}
}).then(response => {
for (var i in response) {
if (response[i]["name"].endsWith(`(${labelShort})`)) {
var pid = response[i]["id"]

url = new URL('https://api.track.toggl.com/api/v8/tasks')
data = {
"task": {
"name": `${labelShort}_${idShort}`,
"pid": pid
}
}
trektor.fetchJSON(url.toString(), {
method: 'POST',
headers: {
'Authorization': `Basic ${togglAuth}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
}
}
})
})

})
})


function addButton() {
const sidebar = document.querySelector('.window-sidebar');
const button = document.createElement('span');
button.classList.add('button-link');
button.addEventListener('click', onClick);
sidebar.prepend(button);

const buttonIcon = document.createElement('span');
buttonIcon.classList.add('icon-sm', 'plugin-icon');
buttonIcon.innerText = '+';
button.append(buttonIcon);

const buttonText = document.createElement('span');
buttonText.innerText = 'Toggl Task';
button.append(buttonText);

sidebar.querySelector('.mod-no-top-margin').classList.remove('mod-no-top-margin');
sidebar.querySelector('.js-sidebar-add-heading').classList.remove('mod-no-top-margin');
}

window.addEventListener("pushstate", function () {
if (window.location.pathname.startsWith("/c/")) {
addButton()
}
})
window.addEventListener('pushstate', () => {
if (window.location.pathname.startsWith('/c/')) {
addButton();
}
});
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "Trektor",
"description": "Browser-Extension zum automatischen Anlegen von Toggl tracking tasks",
"version": "0.0.1",
"version": "1.1.0",
"icons": {
"64": "icons/64.png"
},
Expand Down
1 change: 1 addition & 0 deletions node_modules/.bin/acorn

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/eslint

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/js-yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/json5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/node-which

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/resolve

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/rimraf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading