I offer to you to use in this Libraries:
- InboxSdk - high level JavaScript library used to easily build browser extensions that interact with both Gmail and Inbox by Google.
- Gmail library github - Great library that using the DOM for many options of gmail
Best option for you I think will be InboxSdk. First you need to register your app here ,Then on your content page of your chrome-extension set :
InboxSDK.load('1.0', 'YOUR_APP_ID_HERE').then(function(sdk){
In this function you need to perform all actions . You could register events ( like when you read/compose message etc.) but your purpose is to add button to tool bar so you need to add a toolbar event:
registerToolbarButtonForList(toolbarButtonDescriptor)
or
registerToolbarButtonForThreadView(toolbarButtonDescriptor)
or
addToolbarButtonForApp(appToolbarButtonDescriptor)
If you want to know specific about every register event go to here
The object the event get it's all the deatils about the button(name, on click event etc) , see this here . From here you could set what ever you want from your button in the object .
Good luck