1- let engine ;
2-
3- if ( window . browser !== undefined ) {
4- engine = browser ;
5- } else {
6- engine = chrome ;
7- }
8-
91function addButton ( ) {
102 const sidebar = document . querySelector ( ".window-sidebar" )
113 const button = document . createElement ( 'span' ) ;
@@ -37,7 +29,7 @@ const mappings = {
3729
3830function onClick ( ) {
3931 let trelloApiKey = "afadffe77f745496f80ebb4bf460c615"
40- engine . storage . local . get ( ) . then ( result => {
32+ trektorStorage . get ( [ 'trello' , 'toggl' ] ) . then ( result => {
4133 const trelloToken = result . trello
4234 const togglToken = result . toggl
4335
@@ -94,12 +86,12 @@ function onClick() {
9486
9587 url = new URL ( "https://api.track.toggl.com/api/v8/workspaces" )
9688 const togglAuth = btoa ( `${ togglToken } :api_token` )
97- fetch ( url . toString ( ) , {
89+ trektorRuntime . sendMessage ( [ url . toString ( ) , {
9890 headers : {
9991 'Authorization' : `Basic ${ togglAuth } ` ,
10092 'Content-Type' : 'application/json'
10193 }
102- } ) . then ( response => response . json ( ) ) . then ( response => {
94+ } ] ) . then ( response => {
10395 for ( var i in response ) {
10496 if ( response [ i ] [ "name" ] == "aboutsource" ) {
10597 var wid = response [ i ] [ "id" ]
@@ -111,12 +103,12 @@ function onClick() {
111103 }
112104
113105 url = new URL ( `https://api.track.toggl.com/api/v8/workspaces/${ wid } /projects` )
114- fetch ( url . toString ( ) , {
106+ trektorRuntime . sendMessage ( [ url . toString ( ) , {
115107 headers : {
116108 'Authorization' : `Basic ${ togglAuth } ` ,
117109 'Content-Type' : 'application/json'
118110 }
119- } ) . then ( response => response . json ( ) ) . then ( response => {
111+ } ] ) . then ( response => {
120112 for ( var i in response ) {
121113 if ( response [ i ] [ "name" ] . endsWith ( `(${ labelShort } )` ) ) {
122114 var pid = response [ i ] [ "id" ]
@@ -128,14 +120,14 @@ function onClick() {
128120 "pid" : pid
129121 }
130122 }
131- fetch ( url . toString ( ) , {
123+ trektorRuntime . sendMessage ( [ url . toString ( ) , {
132124 method : 'POST' ,
133125 headers : {
134126 'Authorization' : `Basic ${ togglAuth } ` ,
135127 'Content-Type' : 'application/json'
136128 } ,
137129 body : JSON . stringify ( data )
138- } )
130+ } ] )
139131 }
140132 }
141133 } )
0 commit comments