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 5 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
56 changes: 48 additions & 8 deletions content_script.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,68 @@
function addButton(){
const sidebar = document.querySelector(".window-sidebar")
const button = document.createElement('span');
let sidebar = document.querySelector(".window-sidebar")
let button = document.createElement('span');
Comment thread
ushi-as marked this conversation as resolved.
Outdated
button.classList.add('button-link');
button.addEventListener('click', onClick);
sidebar.prepend(button);

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

const buttonText = document.createElement('span');
let 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")
}

function onClick(){
alert("work in progress ;)")
var mappings = []
mappings["GG"] = "gg"
mappings["Audience Builder"] = "ab"
mappings["Audience Explorer"] = "ae"
mappings["Cta Calls"] = "xcta"
mappings["Camper"] = "camper"
Comment thread
This conversation was marked as resolved.
Outdated

function onClick() {
let apiKey = "afadffe77f745496f80ebb4bf460c615"
//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")
let longId = window.location.href.split("/")[4]
Comment thread
This conversation was marked as resolved.
Outdated
var url = 'https://api.trello.com/1/cards/' + longId + '?key=' + apiKey + '&token=' + token
Comment thread
ushi-as marked this conversation as resolved.
Outdated
fetch(url).then(response => response.json()).then(response => {
shortId = response["idShort"]

if (!response["name"].endsWith(shortId)) {
for (var i in response["labels"]) {
var labelShort = mappings[response["labels"][i]["name"]]
console.log(labelShort)
}

if (labelShort != undefined) {
const fixedEncodeURIComponent = (str) => {
return encodeURIComponent(str).replace(/[!'()*]/g, (c) => {
return '%' + c.charCodeAt(0).toString(16);
});
}
var url = 'https://api.trello.com/1/cards/' + longId + '?name=' + fixedEncodeURIComponent(response["name"]) + fixedEncodeURIComponent(" #") + labelShort + "_" + shortId + '&key=' + apiKey + '&token=' + token
console.log(url)
fetch(url, {
method: 'PUT'
}).then(response => {//response.json()).then(response => {
Comment thread
ushi-as marked this conversation as resolved.
Outdated
console.log(response)
console.log("HURRA!")
})
}
}
Comment thread
ushi-as marked this conversation as resolved.

})
}

window.addEventListener("pushstate", function(){
if(window.location.pathname.startsWith("/c/")){
window.addEventListener("pushstate", function () {
if (window.location.pathname.startsWith("/c/")) {
addButton()
}
})
4 changes: 4 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
}
],

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

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