📜 ⬆️ ⬇️

"Validity" extensions for Firefox and a couple of little things

Hello!

On Habré there are a lot of articles on the topic of writing extensions for Mozilla Firefox.
Using the search, you can find information, for example: here , here , here or even here .

But I have not yet found (if there is, then - sorry) articles about valid extensions.
')
At the same time, the Developer Extensions Validator has existed for quite a long time: here at the bottom of the page, you need a login to enter .

I will not copy the information given in the articles above, with your permission.
Instead, I will try to describe the general principles for creating a “valid” supplement.

And I’ll also give you a couple of examples and add links.





What else can you think of to make your life harder:

  1. For your XUL overlay, it is advisable to create only one (there should be only one, as in “Gorce”) a JS file, which will be “all your code”.

    Moreover, the entire code of this file will be inside the circuit, like this:

    ( function (){
    var e;
    try {

    [ ]

    } catch (e){ window.alert(e); }
    })();

    * This source code was highlighted with Source Code Highlighter .


  2. Do you want the code to be “scattered” in “a bunch of small files in a bunch of directories?

    This is also possible!

    var JS_Loader = function ( path_to_file, object_where_file_will_be_loaded ){

    Components.classes[ '@mozilla.org/moz/jssubscript-loader;1' ]
    .getService(Components.interfaces.mozIJSSubScriptLoader)
    .loadSubScript( path_to_file , object_where_file_will_be_loaded ); }
    }

    var our_scope_object = {};

    // USING:

    JS_Loader( 'some_path to chrome:// or resource://' , our_scope_object);

    /*

    , "" 'some_path' our_scope_object.
    , 'some_path' this our_scope_object

    */


    * This source code was highlighted with Source Code Highlighter .


    If this option is not satisfactory due to the well-known "glitches", and, by the way, due to the fact that the Warning fails during validation, then you should do it "completely correctly" through:

    Components.utils.import( path_to_file , object_where_file_will_be_loaded )

    * This source code was highlighted with Source Code Highlighter .


    Although, there will be a little bit other "troubles".

  3. In general, it is possible, of course, to remove all actions for “hanging” “ addEventListener ” for controls into a separate function ... But then you need to remember that there are “incidents” if you try to register events for non-existent controls.

    Among other things, this will help us !:

    window.addEventListener( "aftercustomization" , function (evt){

    [ , <br> , toolbar ]

    }, false );


    * This source code was highlighted with Source Code Highlighter .




Finally, let a couple of "pleasant" little things:

Work with properties "extensions".

var ADDON_ID = '[ em:id install.rdf ]' ;
var EXTENSION = {};
if (Application.extensions){ EXTENSION = Application.extensions.get(ADDON_ID); }
else { Application.getExtensions( function (extensions){ EXTENSION = extensions.get(ADDON_ID); }); }
return {
ext : function (){ return EXTENSION; }
, ver : function (){ return EXTENSION.version; }
}


* This source code was highlighted with Source Code Highlighter .


File system extension path:

var addonLocation = '' ;
Components.utils.import( "resource://gre/modules/AddonManager.jsm" );
AddonManager.getAddonByID( '[ em:id install.rdf ]' , function (addon) {
addonLocation = addon.getResourceURI( "" ).QueryInterface(Components.interfaces.nsIFileURL).file;
} );


* This source code was highlighted with Source Code Highlighter .


Twinkler ...

var blinker = function (cnt){
for ( var i = 1; i < cnt; i++){
( function (ist){
// window.alert('' + ist + ' ' + (ist % 2));
window.setTimeout( function (){ show_status((ist % 2)); }, ist*450 );
})(i);
}
}

/*
  
show_status, , 1 0

"" , - ""
  
*/


* This source code was highlighted with Source Code Highlighter .


In conclusion, I would like to give a couple of references:

Does not need comments: addons.mozilla.org/en-US/developers
Mozilla Developer Network: developer.mozilla.org/en-US

We look through "this" with care .:
XUL Specification: developer.mozilla.org/en/XUL
developer.mozilla.org/en/JavaScript
developer.mozilla.org/en/DOM
developer.mozilla.org/en/XUL_Overlays
developer.mozilla.org/en/XUL_controls

And this is sure to review !:
developer.mozilla.org/en/Setting_up_extension_development_environment
developer.mozilla.org/en/Extension_Frequently_Asked_Questions
developer.mozilla.org/en/Creating_toolbar_buttons
developer.mozilla.org/en/XUL_School/Adding_Toolbars_and_Toolbar_Buttons
developer.mozilla.org/en/XUL_School/Adding_Events_and_Commands
developer.mozilla.org/en/Addons/Add-on_Manager/Code_Samples
developer.mozilla.org/en/chrome_registration
developer.mozilla.org/en/XPCOM_Interface_Reference/mozIJSSubScriptLoader

And about this sometime, probably, we will remember ...:
developer.mozilla.org/en/Code_snippets
developer.mozilla.org/en/XUL_School/Handling_Preferences
developer.mozilla.org/en/Security_best_practices_in_extensions

Source: https://habr.com/ru/post/134413/


All Articles