Tutorials: Intro, command

Introduction to Scripting in ChatZilla

Prerequisites

  1. ChatZilla 0.9.78+ (get the latest version). You can check what version you have by entering the command /about into ChatZilla.
  2. Basic knowledge and understanding of JavaScript, preferably including exception handling (try/catch). If not, there's no reason to not read these tutorials, but you'll probably want at least the Mozilla Developer Center JavaScript 1.5 Guide open to look up various JavaScript usage, and possibly a friend who does know JavaScript.
  3. A text editor you are comfortable editing plain JavaScript in. On Windows, Notepad will do, but there's plenty of decent editors that can syntax-highlight JavaScript. Same goes for Linux, something like nano is fine, but there's other editors that might make it easier to see what's going on.
  4. A note about paths. All paths in these documents, such as "profilePath/chatzilla/scripts", use "/" to seperate elements of the path (known as the 'path seperator'). This is how Unix, and it's variant (e.g. Linux) do things, and also how URLs work. When working on Windows, you will usually need to use "\" to separate the path elements.

Some other things you might want to check right now:

  • The location for ChatZilla plugins.
    1. Enter "/pref profilePath" into chatZilla. This is the base directory for all of ChatZilla's files on your system.
    2. This directory should have a "scripts" subdirectory.
    3. This directory will be referred to as "profilePath/chatzilla/scripts" for the rest of the tutorials.
  • Check what plugins you are already using.
    1. Enter "/pref initialScripts" into ChatZilla, and check the output.
    2. If this contains anything other than the full path to "profilePath/chatzilla/scripts", and you want to reset it to the default, enter "/pref initialScripts -".

How "initialScripts" Works

ChatZilla allows two kinds of file: URLs in this list preference:

  • .js files, which are loaded directly.
  • Directories, which are scanned for:
    • "init.js" in the directory - loaded if found, processing continues.
    • One level of subdirectories checked for "init.js" - loaded if found, processing continues.

The idea of this is that any plugin people make can be set up to work from one directory, and that directory can just be placed into "profilePath/chatzilla/scripts" and it'll work, using "init.js" as a bootstrap.

Base Plugin

Here is the basic code you'll need in all your plugins:

   plugin.id = "unique-id";
   
   plugin.init =
   function _init(glob) {
       plugin.major = 1;  // Major version number.
       plugin.minor = 0;  // Minor version number.
       plugin.version = plugin.major + "." + plugin.minor;
       plugin.description = "My plugin description";
   }
   
   plugin.enable =
   function _enable() {
       return true;
   }
   
   plugin.disable =
   function _disable() {
       return true;
   }

The plugin's ID must consist of only the letters 'a' through 'z', '-' and '_' (upper case or lower case). The "init" method is called once when the plugin is loaded. The "enable" and "disable" methods should return true if they succeed. All the tutorials will build on this base plugin code.

All plugins from these tutorials will be placed into their own subdirectory within "profilePath/chatzilla/scripts" and called "init.js".

You can also find all the tutorial samples in the sample code directory.

Next tutoral: Creating a Command

Powered by the Content Parser System, copyright 2002 - 2009 James G. Ross.