I'm looking into creating an extension for Firefox/Chrome that creates a button in the toolbar. When clicked, it should load a bookmarklet (basically a piece of js).
Any good resources to start with?
Tha开发者_运维知识库nks!
If you want to modify the browser itself, you would need to create an extension, not a bookmarklet.
Bookmarklet are just javascript code that will be executed when you add a bookmark on the toolbar (or anything) that has code. If that is the UI your looking for, then that is great. Just create something like:
javascript:alert('bookmark clicked');
If you want a browser action, you need to package it up as an extension. For Google Chrome, you can visit the docs and API http://code.google.com/chrome/extensions/browserAction.html there are many examples on how to create one by searching StackOverflow.
For example:
chrome.browserAction.onClicked.addListener(function(tab) {
alert('brower action clicked');
}));
To build an extension in Firefox, you would need to follow their guide here https://developer.mozilla.org/en/Building_an_Extension
For Firefox you can use the Custom Buttons extension. Not sure but Custom Toolbar Button extension for Chrome might allow executing your bookmarklet as well - or you can use it as a starting point for your own extension.
I just did something similar, so that I could do a focus group to see whether users prefered an extension to a bookmarklet. All I did was create a very basic extension that just executed
location.assign("Your bookmarklet contents here");
This is pretty much functionally equivalent to a user clicking the bookmarklet on a web page. The only real difference I had to account for was making sure the page was done loading before running that. That may not be an issue for your needs, but it was for mine.
加载中,请稍侯......
精彩评论