Revision 236976 of Writing GCLI Commands

  • Revision slug: Tools/GCLI/Writing_GCLI_Commands
  • Revision title: Writing GCLI Commands
  • Revision id: 236976
  • Created:
  • Creator: joewalker
  • Is current revision? No
  • Comment 123 words added

Revision Content

Types

Out of the box we support:

  • The obvious basic types: string, number, boolean
  • setting, settingValue: i.e. prefs (settingValue is string, number, or boolean depending on the underlying type of the setting)
  • node: A single node on the page referenced by CSS expression
  • resource: A CSS or JavaScript file in the page

We're also working on date and file types, but they're not ready yet. For now you should use string.

Further Documentation

The GCLI project contains several pages of relevant documentation:

Access to Firefox

When a command is executed, it is passed 2 parameters, args and context. This are both explained in the GCLI documentation. Firefox provides an environment which contains the following:

  • chromeDocument: Allows access to the browser environment
  • contentDocument: Allows access to the current web page

So for example:

gcli.addCommand({
  name: 'closebrowserwindow',
  exec: function(args, context) {
    context.environment.chromeDocument.defaultView.close();
  }
});

Or:

gcli.addCommand({
  name: 'countdivs',
  exec: function(args, context) {
    return context.environment.contentDocument.querySelectorAll('div').length;
  }
});

Revision Source

<h3>Types</h3>
<p>Out of the box we support:</p>
<ul> <li>The obvious basic types: <code>string</code>, <code>number</code>, <code>boolean</code></li> <li><code>setting</code>, <code>settingValue</code>: i.e. prefs (settingValue is string, number, or boolean depending on the underlying type of the setting)</li> <li><code>node</code>: A single node on the page referenced by CSS expression</li> <li><code>resource</code>: A CSS or JavaScript file in the page</li>
</ul>
<p>We're also working on date and file types, but they're not ready yet. For now you should use <code>string</code>.</p>
<h3>Further Documentation</h3>
<p>The GCLI project contains several pages of relevant documentation:</p>
<ul> <li><a class="link-https" href="https://github.com/joewalker/gcli/blob/master/docs/index.md" title="https://github.com/joewalker/gcli/blob/master/docs/index.md">Documentation Index</a></li> <li><a class="link-https" href="https://github.com/joewalker/gcli/blob/master/docs/writing-commands.md" title="https://github.com/joewalker/gcli/blob/master/docs/writing-commands.md">Writing Commands</a></li> <li><a class="link-https" href="https://github.com/joewalker/gcli/blob/master/docs/writing-types.md" title="https://github.com/joewalker/gcli/blob/master/docs/writing-types.md">Writing Types</a></li>
</ul>
<h2>Access to Firefox</h2>
<p>When a command is executed, it is passed 2 parameters, <code>args</code> and <code>context</code>. This are both <a class=" link-https" href="https://github.com/joewalker/gcli/blob/master/docs/writing-commands.md#the-command-function-exec" title="https://github.com/joewalker/gcli/blob/master/docs/writing-commands.md#the-command-function-exec">explained in the GCLI documentation</a>. Firefox provides an environment which contains the following:</p>
<ul> <li><code>chromeDocument</code>: Allows access to the browser environment</li> <li><code>contentDocument</code>: Allows access to the current web page</li>
</ul>
<p>So for example:</p>
<pre>gcli.addCommand({
  name: 'closebrowserwindow',
  exec: function(args, context) {
    context.environment.chromeDocument.defaultView.close();
  }
});
</pre>
<p>Or:</p>
<pre>gcli.addCommand({
  name: 'countdivs',
  exec: function(args, context) {
    return context.environment.contentDocument.querySelectorAll('div').length;
  }
});
</pre>
Revert to this revision