<commit_before><!-- MAIN CONTENT -->
<h5 class="page-header"><a id="content" name="content">Writing User Scripts</a></h5>

<p>You can write your very own shiny user script with just a few steps:</p>

<h6>1. Create the file</h6>
<p>Open a new text file in your favorite editor and throw some javascript in there.</p>
<p>Note that there are <a href="http://www.amazon.com/exec/obidos/tg/detail/-/1565923928/103-6951853-4103063?v=glance">many</a> good <a href="http://www.google.com/search?q=dhtml+tutorial">resources</a> available if you're not sure exactly what javascript you need.</p> 
<pre>(function() {
    alert("Hello, world!");
})();</pre>
<p>Also note that it's a good practice (though not required) to wrap the entire thing in an anonymous function to keep from creating new global names which might interfere with the target webpage.</p>

<h6>2. Save the file</h6>
<p>You can choose any name, but it has to end with <strong>.user.js</strong>.</p>

<h6>3. Test the file</h6>
<p>Drag the file onto Firefox (or open it any other way) and select "Install User Script..." from the Tools menu. <em>Note that this option will be disabled if you forgot to name your file ending with ".user.js".</em></p>

<h6>4. (optional) Add metadata</h6>
<p>By default, scripts will be installed with a name based on their filename, a namespace based on the URL they were downloaded from, and will be included with every site. If you want to override these defaults, you need metadata.</p>
<p>Medatadata is added with special javascript comments, like so:</p>
<pre>// ==UserScript==
// @name          Say Hello!
// @namespace     http://youngpup.net/userscripts
// @description	  Greets the world
// @include       http://google.com/*
// @include       http://www.google.com/*
// @exclude       http://gmail.google.com/*
// ==/UserScript==

(function() {
    alert("Hello, world!");
})();</pre>
<p>Here is a short reference of the available tags:</p>
<p>
  <table border="1">
    <thead>
      <tr>
        <th>Property</th>
        <th>Description</th>
        <th>Multiplicity</th>
        <th>Default</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>@name</td>
        <td>A friendly name for the script.</td>
        <td>0-1</td>
        <td>The script's filename without the extension.</td>
      </tr>
      <tr>
        <td>@namespace</td>
        <td>A scope within which @name should be unique.</td>
        <td>0-1</td>
        <td>The domain of the script's file.</td>
      </tr>
      <tr>
        <td>@description</td>
        <td>A, uhm, description.</td>
        <td>0-1</td>
        <td>none</td>
      </tr>
      <tr>
        <td>@include</td>
        <td>A url to include the script with. There can be more than one.</td>
        <td>0+</td>
        <td>one, set to *</td>
      </tr>
      <tr>
        <td>@exclude</td>
        <td>A url to explicitly exclude the script from. There can be more than one.</td>
        <td>0+</td>
        <td>none</td>
      </tr>
    </tbody>
  </table>
</p>

<h6>Tips</h6>
<ul>
  <li>User scripts are injected into the document after the DOM is fully loaded, but before onload occurs. This means that your scripts can begin immediately and don't need to wait for onload.</li>
  <li>Mozilla has a bunch of advanced features that you can take advantage of to make your job easier. These typically aren't practical for DHTML authors because they don't exist in any other browser, but since your user scripts will only run on firefox, you're free to use such goodies as <a href="http://www-jcsu.jesus.cam.ac.uk/~jg307/mozilla/xpath-tutorial.html">xpath</a> support (for HTML as well as XHTML), <a href="http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html">treewalkers</a>, <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html">mutation events</a>, <a href="http://xulplanet.com/references/objref/XMLHttpRequest.html">xmlhttp</a>, etc.</li>
</ul><commit_msg>*** empty log message ***<commit_after><!-- MAIN CONTENT -->
<h5 class="page-header"><a id="content" name="content">Writing User Scripts</a></h5>

<p>You can write your very own shiny user script with just a few steps:</p>

<h6>1. Create the file</h6>
<p>Open a new text file in your favorite editor and throw some javascript in there. Note that there are <a href="http://www.amazon.com/exec/obidos/tg/detail/-/1565923928/103-6951853-4103063?v=glance">many</a> good <a href="http://www.google.com/search?q=dhtml+tutorial">resources</a> available if you're not sure exactly what javascript you need.</p> 
<p>For example, you might create this simple script:</p>
<pre>(function() {
    alert("Hello, world!");
})();</pre>
<p>Also notice that it's a good practice (though not required) to wrap the entire script in an anonymous function to avoid creating new global names which might interfere with the target webpage.</p>

<h6>2. Save the file</h6>
<p>You can choose any name, <em>but it has to end with <strong>.user.js</strong></em>.</p>

<h6>3. Test the file</h6>
<p>Drag the file onto Firefox (or open it any other way) and select "Install User Script..." from the Tools menu. <em>Note that this option will be disabled if you forgot to name your file ending with ".user.js".</em></p>

<h6>4. (optional) Add metadata</h6>
<p>By default, scripts will be installed with a name based on their filename, a namespace based on the URL they were downloaded from, and will be included with every page on the interwebs. If you want to override this default behavior, you need metadata power.</p>
<p>Medatadata is added to userscripts with special javascript comments, like so:</p>
<pre>// ==UserScript==
// @name          Say Hello!
// @namespace     http://youngpup.net/userscripts
// @description	  Greets the world
// @include       http://google.com/*
// @include       http://www.google.com/*
// @exclude       http://gmail.google.com/*
// ==/UserScript==

(function() {
    alert("Hello, world!");
})();</pre>
<p>Here is a short reference of the available metadata tags:</p>
<p>
  <table border="1">
    <thead>
      <tr>
        <th>Property</th>
        <th>Description</th>
        <th>Multiplicity</th>
        <th>Default</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>@name</td>
        <td>A friendly name for the script.</td>
        <td>0-1</td>
        <td>The script's filename without the extension.</td>
      </tr>
      <tr>
        <td>@namespace</td>
        <td>A scope within which @name should be unique.</td>
        <td>0-1</td>
        <td>The domain of the script's file.</td>
      </tr>
      <tr>
        <td>@description</td>
        <td>A, uhm, description.</td>
        <td>0-1</td>
        <td>none</td>
      </tr>
      <tr>
        <td>@include</td>
        <td>A url to include the script with. There can be more than one.</td>
        <td>0+</td>
        <td>one, set to *</td>
      </tr>
      <tr>
        <td>@exclude</td>
        <td>A url to explicitly exclude the script from. There can be more than one.</td>
        <td>0+</td>
        <td>none</td>
      </tr>
    </tbody>
  </table>
</p>
<br />
<h6>Tips</h6>
<ul>
  <li>User scripts are injected into the document after the DOM is fully loaded, but before onload occurs. This means that your scripts can begin immediately and don't need to wait for onload.</li>
  <li>Mozilla has a bunch of advanced features that you can take advantage of to make your job easier. These typically aren't practical for DHTML authors because they don't exist in any other browser, but since your user scripts will only run on firefox, you're free to use such goodies as <a href="http://www-jcsu.jesus.cam.ac.uk/~jg307/mozilla/xpath-tutorial.html">xpath</a> support (for HTML as well as XHTML), <a href="http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html">treewalkers</a>, <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html">mutation events</a>, <a href="http://xulplanet.com/references/objref/XMLHttpRequest.html">xmlhttp</a>, etc.</li>
</ul>
{'fraction_non_alphanumeric': 0.15232616308154076, 'fraction_numerical': 0.014757378689344673, 'mean_word_length': 3.02061337355455, 'pattern_counts': {'":': 0, '<': 260, '<?xml version=': 0, '>': 260, 'https://': 0, 'lorem ipsum': 0, 'www.': 12, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1831351', 'n_tokens_mistral': 2661, 'n_tokens_neox': 2557, 'n_words': 895}