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
138 changes: 101 additions & 37 deletions content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,119 @@ function addButton() {
}

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

function onClick() {
let apiKey = "afadffe77f745496f80ebb4bf460c615"
let apiKey = "***"
//generate token at https://trello.com/1/authorize?expiration=never&scope=read,write,account&response_type=token&name=Server%20Token&key=afadffe77f745496f80ebb4bf460c615
let token = "***"
console.log("Hallo")
const longId = window.location.pathname.split("/")[2];
var url = `https://api.trello.com/1/cards/${longId}?key=${apiKey}&token=${token}`
fetch(url).then(response => response.json()).then(response => {
shortId = response["idShort"]

if (!response["name"].endsWith(shortId)) {
for (var i in response["labels"]) {
if (labelShort == undefined) {
var labelShort = mappings[response["labels"][i]["name"]]
} else if (mappings[response["labels"][i]["name"]] != undefined) {
alert(`Diese Karte hat sowohl "${labelShort}" als auch "${mappings[response["labels"][i]["name"]]}".`)
}
}
let token = "af00d9597af9fb897f6b2fedb3b7152845991fe186caca08cf5dbb03bba40ffc"
let togglToken = "***"

const idLong = window.location.pathname.split("/")[2];
var url = new URL(`https://api.trello.com/1/cards/${idLong}?key=${apiKey}&token=${token}`)
fetch(url.toString()).then(response => response.json()).then(response => {
const idShort = response["idShort"]

if (labelShort != undefined) {


const url = new URL(`https://api.trello.com/1/cards/${longId}`)
console.log(url)

const data = {
"name": `${response["name"]} #${labelShort}_${shortId}`
};
const jsonBody = JSON.stringify(data);
fetch(url.toString(), {
method: 'PUT',
headers: {
'Authorization': `OAuth oauth_consumer_key="${apiKey}", oauth_token="${token}"`,
'Content-Type': 'application/json'
},
body: jsonBody
}).then(response => {
console.log(response)
})
console.log("Hallo")
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 in den mappings vorhandenes 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="${apiKey}", oauth_token="${token}"`,
'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`)
fetch(url.toString(), {
headers: {
'Authorization': `Basic ${togglAuth}`,
'Content-Type': 'application/json'
}
}).then(response => response.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`)
fetch(url.toString(), {
headers: {
'Authorization': `Basic ${togglAuth}`,
'Content-Type': 'application/json'
}
}).then(response => response.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
}
}
fetch(url.toString(), {
method: 'POST',
headers: {
'Authorization': `Basic ${togglAuth}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then(response => {
console.log(response)
})
}
}
})
})

})
}

Expand Down
5 changes: 3 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
],

"permissions": [
"*://api.trello.com/*"
"*://api.trello.com/*",
"*://*.toggl.com/*"
],

"options_ui": {
"page": "options/index.html"
}
}
}