Re: Amazon widget



Hi Stormy,

Stormy Peters wrote:
The GNOME Foundation has an Amazon affiliates account.

Dave Neary asked for the code to use on his blog (so purchases
contribute to the GNOME Foundation) - the code is gnfo-20.

Cool, thanks.

Then Gabriel Hurt suggested making an Amazon extension like
http://www.iheartmiro.org/. I think that's be a great idea! I'd
certainly add a widget to my version of Firefox that made all my Amazon
purchases benefit the GNOME Foundation.

Does anyone know how to make such a widget? Or know who would?

.xpi Firefox extensions are zip files that you can uncompress with
unzip, and inside you have plain text source files.

The hierarchy is fairly simple:
IHeartMiro/
  /chrome
    /content
      browser.xul
      contents.rdf
      iheartmiro.js
      iheartmiro.png (icon for use in extension manager)
  /components
    iheartmiro.js
  chrome.manifest
  install.rdf
  LICENSE (GPL v3 in the case of I<3Miro)


The manifest file is very simple, it declares a namespace for the
package (iheartmiro) pointing to a location (relative to the root
directory) where content can be found, and then attaches the namespace
to an existing one (browser, mail client, addressbook, etc). In this
one, we're working with the browser UI, so we extend browser.

content iheartmiro  chrome/content/
overlay chrome://browser/content/browser.xul
chrome://iheartmiro/content/browser.xul

The RDF file is an XML file describing the package, a bit trickier,
including setting a unique package ID (I don't know how these are
generated), stating what versions of Firefox the extension will work
with, and giving a name & description for the extension for the
extensions panel. I think that the best thing to do here is copy & paste
an existing one & make whatever changes you need :)

The main work is done in the content directory pointed to  in the
manifest, chrome/content.

browser.xul is loaded when you start the browser, and does nothing
except launch the Javascript chrome/content/iheartmiro.js as far as I
can tell.

chrome/content/iheartmiro.js loads the iheartmiro.js file in components
and creates an instance of the iHeartMiroObserver class. It seems like
there's a standard interface to implement here: register, unregister,
QueryInterface and observe. register is called on instantiation,
unregister on unloading (they seem to be stock methods), and observe is
the meat of the function, and defines the hook which will be used to
hook into the Amazon affiliate programme.

Every time we load a page (topic == 'http-on-modify-request'), we run
the iHeartMiro.onLoad function.

If the URI is in the set (www.)amazon.(com|at|fr|ca|de|co.uk|co.jp|jp)
or amazone.com, we get the appropriate affiliate code for the
appropriate site, generate the affiliate URL, and automatically replace
the entry URL with ours.

Aside from that, there's some template code for registering IHeartMiro
as a component which I don't understand, although it looks like we'll
have to be careful with classIDs, contractIDs. To my untrained eye, it
looks like we can just s/IHeartMiro/IHeartGnome and we're more than 80%
of the way there.

Am I missing something important?

Afterwards, for packaging, it's a case of running
zip IHeartGnome.xpi IHeartGnome

Once you have modified the install.rdf and the other files appropriately.

I know it'll probably take less time to redo the package than I've spent
on this email :} but hopefully someone else will be able to navigate the
annoying little details of modifying the various RDF, js and xul files
appropriately?

Stormy, do we have affiliate codes for amazons other than .com?

Cheers,
Dave.

-- 
Dave Neary
GNOME Foundation member
dneary gnome org



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]