Donnerstag, November 08, 2007

write my own firefox plugin

As I don't use/like iTunes I download podcast directly from the RSS feed or the web page. Using Save Link As ... of the browser doesn't really work if you download a bulk of podcasts at the same time. So far I copy links by hand into a file and throw this at wget. This works fine. But to optimize this I would like to be able to add the link directly from firefox to the download file.

For this I need write my own plugin. I found the start point on how to write a firefox plugin on lifehacker some time ago.

This are the steps I used to write my plugin. In the lifehacker article and the referenced links you get the details.

create a new profile and set (about:config)
javascript.options.showInConsole = true
javascript.options.strict = true

not found:
nglayout.debug.disable_xul_cache = true
browser.dom.window.dump.enabled = true

install extensions:
JavaScript Debugger
Console
Chrome List
Firebug

Download the example from Mozilla knowledge base as a starting point.
install.rdf: increase the em:maxVersion to the firefox version used
overlay.xul: add the entry for your own context menu entry
  <popup id="contentAreaContextMenu"> 
<menuitem id="yb-context-tagLink"
insertafter="context-bookmarklink"
label="This is my right click"
class="menuitem-iconic"
oncommand="HelloWorld.onContextCommand(event);"/>
</popup>

overlay.js: add the function to be called from the context menu
  onContextCommand: function()
{
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("/tmp/getPodcast");

var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);

foStream.init(file, 0x02 | 0x08 | 0x10, 0666, 0); // write, create if not exists, append
foStream.write(gContextMenu.linkURL+"\n", gContextMenu.linkURL.length+1);
foStream.close();
}

The defined functions are part of an arry initialisation. So don't forget the comma as I did the first time.

Examples on file I/O is on firefox code snippets. Adding an entry to the context menu and getting the URL is from the del.icio.us extension.

Keine Kommentare: