Add a button dynamically to a WebPage from Firefox Addon.

I actually want to add a button to Gmail. When someone opens a email, he/she sees a button and when someone clicks on it, I add a function to it. I know one way but it's very intensive where I use setInterval() every 300 ms and run a function to check if it's Gmail or not and then add a button dynamically. I need something less intensive because I don't want people to have problems running my add on.

I want it all from my add on script so that I can easily communicate between other functions of my add on.

Answers


To add to pages it depends. Pages can do many tricky things (like GitHub using PJAX see this addon on how it was done).

Method 1 - addEventListener to window or gBrowser But most usually you can catch a DOMContentLoaded or load event. Template HERE.

Method 2 - Observe http-on-examine-response and loadContext If the URL of the nsIHTTPChannel matches your pattern then get the contentWindow from the loadContext and then manipulate. I need to make a clean template for this but you can see some messy ones: here and here

Method 3 - Add ProgressListener ProgressListeners are nice because it helps you catch anchor changes, and usually when sites ajax and change page they change the url somehow but it doesnt really load a new page. I'm working on a template for this but it's not ready yet.

Info about addEventListener If you add event listener in some situations it works for when 3rd parameter is true or when false. If you find one that works for your situation it will always work.

To figure out what combination works for you install this addon: event-listener-experiment-DOMC-and-load it's on GitHub so you can install straight from GitHub with this addon GitHub Extension Installer

Install that addon then navigate to your page, look in the browser console to see what feedback you're getting. It will tell you which works for you. If you need more help tell me the site and I will help you figure it out.

Here's a bootstrap template you can use once you figure out the combination:


Need Your Help

Ruby inside C adding to $LOAD_PATH

c++ c ruby ruby-rice

Effectively I want to know if I can, purely through the use of Ruby's C library, append to $LOAD_PATH.