Skip to content
This repository was archived by the owner on Nov 11, 2025. It is now read-only.

Commit d46b7d7

Browse files
author
WendelinPraktikum
authored
Merge pull request #4 from aboutsource/feature/5253
Feature/5253
2 parents 25daf81 + eacb62f commit d46b7d7

2 files changed

Lines changed: 60 additions & 6 deletions

File tree

content_script.js

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function addButton(){
1+
function addButton() {
22
const sidebar = document.querySelector(".window-sidebar")
33
const button = document.createElement('span');
44
button.classList.add('button-link');
@@ -13,16 +13,66 @@ function addButton(){
1313
const buttonText = document.createElement('span');
1414
buttonText.innerText = 'Toggl Task';
1515
button.append(buttonText);
16-
16+
17+
sidebar.querySelector(".mod-no-top-margin").classList.remove("mod-no-top-margin")
1718
sidebar.querySelector(".js-sidebar-add-heading").classList.remove("mod-no-top-margin")
1819
}
1920

20-
function onClick(){
21-
alert("work in progress ;)")
21+
const mappings = {
22+
"GG": "gg",
23+
"Audience Builder": "ab",
24+
"Audience Explorer": "ae",
25+
"Cta Calls": "xcta",
26+
"Camper": "camper",
27+
};
28+
29+
function onClick() {
30+
let apiKey = "afadffe77f745496f80ebb4bf460c615"
31+
//generate token at https://trello.com/1/authorize?expiration=never&scope=read,write,account&response_type=token&name=Server%20Token&key=afadffe77f745496f80ebb4bf460c615
32+
let token = "***"
33+
console.log("Hallo")
34+
const longId = window.location.pathname.split("/")[2];
35+
var url = `https://api.trello.com/1/cards/${longId}?key=${apiKey}&token=${token}`
36+
fetch(url).then(response => response.json()).then(response => {
37+
shortId = response["idShort"]
38+
39+
if (!response["name"].endsWith(shortId)) {
40+
for (var i in response["labels"]) {
41+
if (labelShort == undefined) {
42+
var labelShort = mappings[response["labels"][i]["name"]]
43+
} else if (mappings[response["labels"][i]["name"]] != undefined) {
44+
alert(`Diese Karte hat sowohl "${labelShort}" als auch "${mappings[response["labels"][i]["name"]]}".`)
45+
}
46+
}
47+
48+
if (labelShort != undefined) {
49+
50+
51+
const url = new URL(`https://api.trello.com/1/cards/${longId}`)
52+
console.log(url)
53+
54+
const data = {
55+
"name": `${response["name"]} #${labelShort}_${shortId}`
56+
};
57+
const jsonBody = JSON.stringify(data);
58+
fetch(url.toString(), {
59+
method: 'PUT',
60+
headers: {
61+
'Authorization': `OAuth oauth_consumer_key="${apiKey}", oauth_token="${token}"`,
62+
'Content-Type': 'application/json'
63+
},
64+
body: jsonBody
65+
}).then(response => {
66+
console.log(response)
67+
})
68+
}
69+
}
70+
71+
})
2272
}
2373

24-
window.addEventListener("pushstate", function(){
25-
if(window.location.pathname.startsWith("/c/")){
74+
window.addEventListener("pushstate", function () {
75+
if (window.location.pathname.startsWith("/c/")) {
2676
addButton()
2777
}
2878
})

manifest.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
}
1919
],
2020

21+
"permissions": [
22+
"*://api.trello.com/*"
23+
],
24+
2125
"options_ui": {
2226
"page": "options/index.html"
2327
}

0 commit comments

Comments
 (0)