views:

333

answers:

1

I have managed to get a custom very basic extension running in Firefox.

What I want to do next is:

  1. Check if the user is on a desired webpage
  2. If yes: check the page on each postback for a hidden element containing a string
  3. If found: launch an external app with string parameter

I have some experience with javascript on webpages, but I don't know how to register my script to run on each webpage opened in firefox and how to access elements within a page.

Hints on where to start would be appreciated...

EDIT: I figured out how to run my code on each page:

addEventListener("DOMContentLoaded", doSomething, false);

EDIT2: I could access page data with event.originalTarget in the handler and run apps with Components.interfaces.nsIProcess

+2  A: 

So what is leftover for you is the DOM traversal and the external program launching.

Your DOM traversal can be done in so many ways. However, here is a simple take

var inputs = document.getElementsByTagName("input");
for (var idx=0; idx<inputs.length; idx++){
    var tp = inputs[idx].attributes['type'].value
    console.log(tp);
    if (tp == 'hidden'){
       // grab your text at here and launch the app.
    }
}

External application launching according to this post

var file = Components.classes["@mozilla.org/file/local;1"]
                     .createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("c:\\myapp.exe");
file.launch();
Tzury Bar Yochay