
The other day I broke off an invite to leprosy. In this connection, there was a desire to experiment with plug-ins to display images from the comments to the post. Not a word further about leprosy, just a few theses about writing and publishing a simple or slightly more than simple add-on for FireFox and Chrome. Well, in the end - links to crafts.
Context
JS code processed on a web page and JS code add-it are processed in different contexts. You will not be able to call spriting functions embedded in a web page from your add-on and vice versa. I will give two examples:
- You have implemented some js-function in add-on (let, displaying previews of pictures from an open starnitsa). To enable the previews, you add the on-in link in the code for the page and write a call to your js-function in the
onclick
event of this link. But such code will not work - a click on the link will be processed in the context of the page, where the add-on functions are not visible. - For DOM manipulation it is convenient to use one of the js frameworks. But even if this framework is included in the web page that your add-on is processing, you will not be able to use it.
Using external js frameworks
In order to be used in its add-on js-framework, it must be inserted directly into the add-on. For FireFox, this is done as follows. First, copy the framework file (in my case, jquery.js) to the “content” directory of your add-on, and then use the external script dynamic loading code:
Components.classes["@mozilla.org/moz/jssubscript-loader;1"].
getService(Components.interfaces.mozIJSSubScriptLoader).
loadSubScript("chrome://leprokartinki/content/jquery.js");
In my case, this code is placed in the
window.addEventListener("load",...)
handler
window.addEventListener("load",...)
The chrome is a bit simpler. You place the file (in my case, jquery.js) in the add-on folder and then simply specify it in manifest.json along with the rest of the js files used.
After these manipulations in add-on, it is possible to use the framework functionality.
')
I could not use the jQuery clone function of
clone()
objects in an add-on. Later I did without cloning. How this feature behaves in the chrome I did not check. There are assumptions about the causes of the error, but I did not dig.
Official publication of add-ons
FireFox allows you to freely publish your crafts to the
gallery and, over time, assigns statuses to add-ons (“Not Verified”, “Pre-Verified”, “Verified”). Between status changes it takes from several days to several weeks. The status of add-on influences its entry into selections and ratings.
But chrome for the possibility of official publication in its
store requires a fee for registration of the developer ($ 5). Only after that your add-on will be available for free download and installation.
Talmud for those who want to try
- Creating an extension for FireFox
- Getstarted for Crome
PS: Two of my crafts - plug-ins to view all the pictures of the post leprosy - I posted
here (FireFox) and
here (Chrome) .
UPD: Another FireFox trick - replaces a Skype phone numbers, found on a web page, with links to a
telephone directory with information about these numbers.