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} )
0 commit comments