Creating a Microsummary

  • Revision slug: Creating_a_Microsummary
  • Revision title: Creating a Microsummary
  • Revision id: 193728
  • Created:
  • Creator: MykMelez
  • Is current revision? No
  • Comment link to the "creating regular expressions" tutorial

Revision Content

A microsummary generator is a set of instructions for creating a microsummary from the content of a page. Web pages can reference generators via <link rel="microsummary"> elements in their <head> elements. Generators can also be independently downloaded and installed by users if they include a list of pages to which they apply.

In this tutorial we're going to create a microsummary generator for the Spread Firefox home page that displays the current Firefox download count along with the label Fx downloads; for example: 174475447 Fx downloads.

We'll build the XSLT transform sheet that converts that page into its microsummary, learn how to specify that the generator applies to that page, and find out how to make the generator available for download and installation.

In each step of revising the transform sheet and other code in this tutorial, new material added will be shown in boldface so you can follow along more easily.

Note: if you are a web site developer, and you want to create microsummaries for pages on your site, you can write generators to do so, but you can also create the microsummaries on the server-side using the same tools and languages you already use to generate pages.

For example, if you use PHP scripts to generate pages on your site, you could write PHP code to output a microsummary when the view=microsummary URL parameter is present. Then just link to the microsummaries from within the pages themselves using a <link rel="microsummary"> element, f.e.:

<head>
  <link rel="microsummary" href="index.php?view=microsummary">
</head>

When Firefox encounters a <link rel="microsummary"> element, it loads the URL in the href attribute. If the URL points to a generator, it uses the generator to generate the microsummary for the page. Otherwise, if the URL returns plain text content (or HTML content that can be converted to plain text), Firefox uses the content as the microsummary for the page.

Beginnings

Generators are expressed as XML documents whose root element is the <generator> element in the http://www.mozilla.org/microsummaries/0.1 namespace. To begin building the generator, create a new empty text file and add an XML declaration and empty <generator> tag to it:

<?xml version="1.0" encoding="UTF-8"?>
<generator xmlns="http://www.mozilla.org/microsummaries/0.1">
</generator>

Giving it a Name

Generators should have name attributes which are arbitrary descriptions of the microsummaries the generator creates. Names should be descriptive enough to give users a good idea what information the microsummaries will provide. Since our generator will be creating microsummaries displaying the Firefox download count, let's give it the name "Firefox Download Count":

<?xml version="1.0" encoding="UTF-8"?>
<generator xmlns="http://www.mozilla.org/microsummaries/0.1"
           name="Firefox Download Count">
</generator>

Adding an XSLT Transform Sheet

Generators must include an XSLT transform sheet (also known as an XSLT stylesheet) which transforms the page content into its microsummary. XSLT is a powerful language for transforming documents into different representations of the same information.

Add the XSLT transform sheet to the generator by including it within a <template> element:

<?xml version="1.0" encoding="UTF-8"?>
<generator xmlns="http://www.mozilla.org/microsummaries/0.1"
           name="Firefox Download Count">
  <template>
    <transform xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">
    </transform>
  </template>
</generator>

Note that while microsummary generators can include arbitrary XSLT, including XSLT that produces rich text output, Firefox currently only displays the text version of the XSLT output.

Specifying the Output Type

Since the XSLT transform sheet will generate a text microsummary, we should indicate this with the XSLT <output> element:

<?xml version="1.0" encoding="UTF-8"?>
<generator xmlns="http://www.mozilla.org/microsummaries/0.1"
           name="Firefox Download Count">
  <template>
    <transform xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <output method="text"/>
    </transform>
  </template>
</generator>

Using a Simple XSLT <template>

The XSLT processor transforms documents by comparing each XSLT <template> element in the transform sheet to a set of nodes in the document. When a <template>'s match attribute matches a node, the processor performs the transformations specified by the content of the element.

This mechanism is powerful, because it lets you traverse the node tree of a document, recursively generating output based on the contents of the document. But for the purposes of generating a microsummary for the Spread Firefox page, we only need to use a single <template> element that matches the root node of the document and is processed once:

<?xml version="1.0" encoding="UTF-8"?>
<generator xmlns="http://www.mozilla.org/microsummaries/0.1"
           name="Firefox Download Count">
  <template>
    <transform xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <output method="text"/>
      <template match="/">
      </template>
    </transform>
  </template>
</generator>

Including the Download Count

To include the download count in the output of the XSLT transform sheet, we need to add an XSLT <value-of> element to the template whose select attribute contains an XPath expression that points to the node containing the count.

XPath is a language for identifying nodes in HTML/XML documents. It also contains basic functions for manipulating those nodes and their content. The easiest way to get an XPath expression that points to the node in question is to use the XPath Checker extension.

Install the extension (restarting Firefox to complete installation) then go to the Spread Firefox home page, find the Firefox download count (a large number at the bottom of the right-hand column), context click on the number, and select View XPath from the context menu.

XPath Checker will open a new window. The new window will include an XPath field that contains this XPath expression pointing to the download count node: id('download-count').

Add a <value-of> element to the XSLT <template> element whose select attribute contains that XPath expression:

<?xml version="1.0" encoding="UTF-8"?>
<generator xmlns="http://www.mozilla.org/microsummaries/0.1"
           name="Firefox Download Count">
  <template>
    <transform xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <output method="text"/>
      <template match="/">
        <value-of select="id('download-count')"/>
      </template>
    </transform>
  </template>
</generator>

Adding Text

To include the label Fx downloads in the microsummary, we need to add an XSLT <text> element to the XSLT <template> element whose content is the text we want to add.

Add a <text> element to the XSLT template with the content Fx downloads:

<?xml version="1.0" encoding="UTF-8"?>
<generator xmlns="http://www.mozilla.org/microsummaries/0.1"
           name="Firefox Download Count">
  <template>
    <transform xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <output method="text"/>
      <template match="/">
        <value-of select="id('download-count')"/>
        <text> Fx downloads</text>
      </template>
    </transform>
  </template>
</generator>

Note that white space between XSLT tags is not included in the XSLT output, unlike in HTML where that white space is collapsed to a single space, so make sure to prepend a space to the phrase in order to separate it from the download count.

With this addition, we've finished writing the XSLT transform sheet that converts the Spread Firefox home page to its microsummary.

Specifying the Page to which the Generator Applies

Now that we've written the transform sheet, we have to specify the page to which it applies. If we were the Spread Firefox webmasters, we might simply reference the generator within the page itself by adding a <link rel="microsummary"> tag to its <head> element:

<head>
  <link rel="microsummary" href="path/to/our/generator.xml">
</head>

Since we're not that site's webmasters, however, we can specify the page to which the generator applies within the generator itself and then make the generator available for download and installation. To specify pages to which a generator applies, we use a <pages> element within the <generator> element:

<?xml version="1.0" encoding="UTF-8"?>
<generator xmlns="http://www.mozilla.org/microsummaries/0.1"
           name="Firefox Download Count">
  <template>
    <transform xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <output method="text"/>
      <template match="/">
        <value-of select="id('download-count')"/>
        <text> Fx downloads</text>
      </template>
    </transform>
  </template>
  <pages>
  </pages>
</generator>

The <pages> element can contain a sequence of <include> and <exclude> elements specifying the pages to which a generator does and doesn't apply, respectively.

To make a generator apply to a page, add an <include> element whose content is a regular expression matching the page. To make the generator not apply to a page, add an <exclude> element whose content is a regular expression matching the page.

By default, generators don't apply to any page, so you have to explicitly list the pages they apply to, and you don't have to exclude any pages unless you've previously included them.

Add an <include> element matching the Spread Firefox home page:

<?xml version="1.0" encoding="UTF-8"?>
<generator xmlns="http://www.mozilla.org/microsummaries/0.1" name="Firefox Download Count">
  <template>
    <transform xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <output method="text"/>
      <template match="/">
        <value-of select="id('download-count')"/>
        <text> Fx downloads</text>
      </template>
    </transform>
  </template>
  <pages>
    <include>http://(www\.)?spreadfirefox\.com/(index\.php)?</include>
  </pages>
</generator>

If you're unfamiliar with regular expressions, see Creating regular expressions for a microsummary generator for a tutorial on writing them.

Making the Generator Available for Download

Now that the generator applies to the Spread Firefox home page, the only thing left to do is to make it downloadable. To do so, we need to put it up on the web and then create a JavaScript link on some web page that calls Firefox's window.sidebar.addMicrosummaryGenerator() method to download and install the generator.

For example, if we put the generator file on the web at http://people.mozilla.com/~myk/microsummaries/tutorial/sfx-generator.xml, and we wanted users to be able to install it from http://people.mozilla.com/~myk/microsummaries/tutorial/index.html, we might add the following code to the index.html page:

<a href="javascript:window.sidebar.addMicrosummaryGenerator('http://people.mozilla.com/~myk/microsummaries/tutorial/sfx-generator.xml')">Install the Spread Firefox home page microsummary!</a>

Clicking that link will generate a JavaScript error on browsers that don't support microsummaries, however, so to improve the experience for those users, we should check to see if the user is using a microsummaries-enabled browser and display an explanatory message if not. We might do so via the following code:

<script>
  const warning = "Sorry, you need a microsummary-enabled browser like Firefox 2.0 to install and use microsummary generators.";
  function addGenerator(url) {
    if (typeof window.sidebar == "object" &&
        typeof window.sidebar.addMicrosummaryGenerator == "function")
      window.sidebar.addMicrosummaryGenerator(url);
    else
     alert(warning);
  }
</script>
<a href="javascript:addGenerator('http://people.mozilla.com/~myk/microsummaries/tutorial/sfx-generator.xml')">Install the Spread Firefox home page microsummary!</a>

Note that due to {{template.Bug(341283)}}, addMicrosummaryGenerator() will not accept a relative URL.

Conclusion

You should now have a microsummary generator that displays the current Firefox download count when you install it, bookmark the Spread Firefox home page, and select the microsummary from the Summary drop-down menu in the Add Bookmark dialog.

For more information about Microsummaries, see the Microsummaries home page.

{{ wiki.languages( { "ca": "ca/Creaci\u00f3_d\'un_microsumari", "fr": "fr/Cr\u00e9ation_d\'un_micror\u00e9sum\u00e9", "it": "it/Creare_un_Microsommario", "pl": "pl/Tworzenie_mikropodsumowania", "ja": "ja/Creating_a_Microsummary" } ) }}

Revision Source

<p>A microsummary generator is a set of instructions for creating a microsummary from the content of a page.  Web pages can reference generators via <code>&lt;link rel="microsummary"&gt;</code> elements in their <code>&lt;head&gt;</code> elements.  Generators can also be independently downloaded and installed by users if they include a list of pages to which they apply.
</p><p>In this tutorial we're going to create a microsummary generator for the <a class="external" href="http://www.spreadfirefox.com/">Spread Firefox home page</a> that displays the current Firefox download count along with the label <cite>Fx downloads</cite>; for example: <cite>174475447 Fx downloads</cite>.
</p><p>We'll build the XSLT transform sheet that converts that page into its microsummary, learn how to specify that the generator applies to that page, and find out how to make the generator available for download and installation.
</p><p>In each step of revising the transform sheet and other code in this tutorial, new material added will be shown in <b>boldface</b> so you can follow along more easily.
</p><p>Note: if you are a web site developer, and you want to create microsummaries for pages on your site, you can write generators to do so, but you can also create the microsummaries on the server-side using the same tools and languages you already use to generate pages.
</p><p>For example, if you use PHP scripts to generate pages on your site, you could write PHP code to output a microsummary when the view=microsummary URL parameter is present.  Then just link to the microsummaries from within the pages themselves using a <code>&lt;link rel="microsummary"&gt;</code> element, f.e.:
</p>
<pre class="eval">&lt;head&gt;
  <b>&lt;link rel="microsummary" href="index.php?view=microsummary"&gt;</b>
&lt;/head&gt;
</pre>
<p>When Firefox encounters a <code>&lt;link rel="microsummary"&gt;</code> element, it loads the URL in the <code>href</code> attribute.  If the URL points to a generator, it uses the generator to generate the microsummary for the page.  Otherwise, if the URL returns plain text content (or HTML content that can be converted to plain text), Firefox uses the content as the microsummary for the page.
</p>
<h2 name="Beginnings"> Beginnings </h2>
<p>Generators are expressed as XML documents whose root element is the <code>&lt;generator&gt;</code> element in the  <cite>http://www.mozilla.org/microsummaries/0.1</cite> namespace.  To begin building the generator, create a new empty text file and add an XML declaration and empty <code>&lt;generator&gt;</code> tag to it:
</p>
<pre class="eval"><b>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</b>
<b>&lt;generator xmlns="<span class="plain">http://www.mozilla.org/microsummaries/0.1</span>"&gt;</b>
<b>&lt;/generator&gt;</b>
</pre>
<h2 name="Giving_it_a_Name"> Giving it a Name </h2>
<p>Generators should have <code>name</code> attributes which are arbitrary descriptions of the microsummaries the generator creates.  Names should be descriptive enough to give users a good idea what information the microsummaries will provide.  Since our generator will be creating microsummaries displaying the Firefox download count, let's give it the name "Firefox Download Count":
</p>
<pre class="eval">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;generator xmlns="<span class="plain">http://www.mozilla.org/microsummaries/0.1</span>"
           <b>name="Firefox Download Count"</b>&gt;
&lt;/generator&gt;
</pre>
<h2 name="Adding_an_XSLT_Transform_Sheet"> Adding an XSLT Transform Sheet </h2>
<p>Generators must include an XSLT transform sheet (also known as an XSLT stylesheet) which transforms the page content into its microsummary.  XSLT is a powerful language for transforming documents into different representations of the same information.
</p><p>Add the XSLT transform sheet to the generator by including it within a <code>&lt;template&gt;</code> element:
</p>
<pre class="eval">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;generator xmlns="<span class="plain">http://www.mozilla.org/microsummaries/0.1</span>"
           name="Firefox Download Count"&gt;
  <b>&lt;template&gt;</b>
    <b>&lt;transform xmlns="<span class="plain">http://www.w3.org/1999/XSL/Transform</span>" version="1.0"&gt;</b>
    <b>&lt;/transform&gt;</b>
  <b>&lt;/template&gt;</b>
&lt;/generator&gt;
</pre>
<p>Note that while microsummary generators can include arbitrary XSLT, including XSLT that produces rich text output, Firefox currently only displays the text version of the XSLT output.
</p>
<h2 name="Specifying_the_Output_Type"> Specifying the Output Type </h2>
<p>Since the XSLT transform sheet will generate a text microsummary, we should indicate this with the XSLT <code>&lt;output&gt;</code> element:
</p>
<pre class="eval">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;generator xmlns="<span class="plain">http://www.mozilla.org/microsummaries/0.1</span>"
           name="Firefox Download Count"&gt;
  &lt;template&gt;
    &lt;transform xmlns="<span class="plain">http://www.w3.org/1999/XSL/Transform</span>" version="1.0"&gt;
      <b>&lt;output method="text"/&gt;</b>
    &lt;/transform&gt;
  &lt;/template&gt;
&lt;/generator&gt;
</pre>
<h2 name="Using_a_Simple_XSLT_.3Ctemplate.3E"> Using a Simple XSLT <code>&lt;template&gt;</code> </h2>
<p>The XSLT processor transforms documents by comparing each XSLT <code>&lt;template&gt;</code> element in the transform sheet to a set of nodes in the document.  When a <code>&lt;template&gt;</code>'s <code>match</code> attribute matches a node, the processor performs the transformations specified by the content of the element.
</p><p>This mechanism is powerful, because it lets you traverse the node tree of a document, recursively generating output based on the contents of the document.  But for the purposes of generating a microsummary for the Spread Firefox page, we only need to use a single <code>&lt;template&gt;</code> element that matches the root node of the document and is processed once:
</p>
<pre class="eval">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;generator xmlns="<span class="plain">http://www.mozilla.org/microsummaries/0.1</span>"
           name="Firefox Download Count"&gt;
  &lt;template&gt;
    &lt;transform xmlns="<span class="plain">http://www.w3.org/1999/XSL/Transform</span>" version="1.0"&gt;
      &lt;output method="text"/&gt;
      <b>&lt;template match="/"&gt;</b>
      <b>&lt;/template&gt;</b>
    &lt;/transform&gt;
  &lt;/template&gt;
&lt;/generator&gt;
</pre>
<h2 name="Including_the_Download_Count"> Including the Download Count </h2>
<p>To include the download count in the output of the XSLT transform sheet, we need to add an XSLT <code>&lt;value-of&gt;</code> element to the template whose <code>select</code> attribute contains an XPath expression that points to the node containing the count.
</p><p>XPath is a language for identifying nodes in HTML/XML documents.  It also contains basic functions for manipulating those nodes and their content.  The easiest way to get an XPath expression that points to the node in question is to use the <a class="external" href="https://addons.mozilla.org/firefox/1095/">XPath Checker extension</a>.
</p><p>Install the extension (restarting Firefox to complete installation) then go to the <a class="external" href="http://www.spreadfirefox.com/">Spread Firefox home page</a>, find the Firefox download count (a large number at the bottom of the right-hand column), context click on the number, and select <cite>View XPath</cite> from the context menu.
</p><p>XPath Checker will open a new window.  The new window will include an <cite>XPath</cite> field that contains this XPath expression pointing to the download count node: <cite>id('download-count')</cite>.
</p><p>Add a <code>&lt;value-of&gt;</code> element to the XSLT <code>&lt;template&gt;</code> element whose <code>select</code> attribute contains that XPath expression:
</p>
<pre class="eval">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;generator xmlns="<span class="plain">http://www.mozilla.org/microsummaries/0.1</span>"
           name="Firefox Download Count"&gt;
  &lt;template&gt;
    &lt;transform xmlns="<span class="plain">http://www.w3.org/1999/XSL/Transform</span>" version="1.0"&gt;
      &lt;output method="text"/&gt;
      &lt;template match="/"&gt;
        <b>&lt;value-of select="id('download-count')"/&gt;</b>
      &lt;/template&gt;
    &lt;/transform&gt;
  &lt;/template&gt;
&lt;/generator&gt;
</pre>
<h2 name="Adding_Text"> Adding Text </h2>
<p>To include the label <cite>Fx downloads</cite> in the microsummary, we need to add an XSLT <code>&lt;text&gt;</code> element to the XSLT <code>&lt;template&gt;</code> element whose content is the text we want to add.
</p><p>Add a <code>&lt;text&gt;</code> element to the XSLT template with the content <cite>Fx downloads</cite>:
</p>
<pre class="eval">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;generator xmlns="<span class="plain">http://www.mozilla.org/microsummaries/0.1</span>"
           name="Firefox Download Count"&gt;
  &lt;template&gt;
    &lt;transform xmlns="<span class="plain">http://www.w3.org/1999/XSL/Transform</span>" version="1.0"&gt;
      &lt;output method="text"/&gt;
      &lt;template match="/"&gt;
        &lt;value-of select="id('download-count')"/&gt;
        <b>&lt;text&gt; Fx downloads&lt;/text&gt;</b>
      &lt;/template&gt;
    &lt;/transform&gt;
  &lt;/template&gt;
&lt;/generator&gt;
</pre>
<p>Note that white space between XSLT tags is not included in the XSLT output, unlike in HTML where that white space is collapsed to a single space, so make sure to prepend a space to the phrase in order to separate  it from the download count.
</p><p>With this addition, we've finished writing the XSLT transform sheet that converts the Spread Firefox home page to its microsummary.
</p>
<h2 name="Specifying_the_Page_to_which_the_Generator_Applies"> Specifying the Page to which the Generator Applies </h2>
<p>Now that we've written the transform sheet, we have to specify the page to which it applies.  If we were the Spread Firefox webmasters, we might simply reference the generator within the page itself by adding a <code>&lt;link rel="microsummary"&gt;</code> tag to its <code>&lt;head&gt;</code> element:
</p>
<pre class="eval">&lt;head&gt;
  <b>&lt;link rel="microsummary" href="path/to/our/generator.xml"&gt;</b>
&lt;/head&gt;
</pre>
<p>Since we're not that site's webmasters, however, we can specify the page to which the generator applies within the generator itself and then make the generator available for download and installation.  To specify pages to which a generator applies, we use a <code>&lt;pages&gt;</code> element within the <code>&lt;generator&gt;</code> element:
</p>
<pre class="eval">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;generator xmlns="<span class="plain">http://www.mozilla.org/microsummaries/0.1</span>"
           name="Firefox Download Count"&gt;
  &lt;template&gt;
    &lt;transform xmlns="<span class="plain">http://www.w3.org/1999/XSL/Transform</span>" version="1.0"&gt;
      &lt;output method="text"/&gt;
      &lt;template match="/"&gt;
        &lt;value-of select="id('download-count')"/&gt;
        &lt;text&gt; Fx downloads&lt;/text&gt;
      &lt;/template&gt;
    &lt;/transform&gt;
  &lt;/template&gt;
  <b>&lt;pages&gt;</b>
  <b>&lt;/pages&gt;</b>
&lt;/generator&gt;
</pre>
<p>The <code>&lt;pages&gt;</code> element can contain a sequence of <code>&lt;include&gt;</code> and <code>&lt;exclude&gt;</code> elements specifying the pages to which a generator does and doesn't apply, respectively.
</p><p>To make a generator apply to a page, add an <code>&lt;include&gt;</code> element whose content is a regular expression matching the page.  To make the generator not apply to a page, add an <code>&lt;exclude&gt;</code> element whose content is a regular expression matching the page.
</p><p>By default, generators don't apply to any page, so you have to explicitly list the pages they apply to, and you don't have to exclude any pages unless you've previously included them.
</p><p>Add an <code>&lt;include&gt;</code> element matching the Spread Firefox home page:
</p>
<pre class="eval">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;generator xmlns="<span class="plain">http://www.mozilla.org/microsummaries/0.1</span>" name="Firefox Download Count"&gt;
  &lt;template&gt;
    &lt;transform xmlns="<span class="plain">http://www.w3.org/1999/XSL/Transform</span>" version="1.0"&gt;
      &lt;output method="text"/&gt;
      &lt;template match="/"&gt;
        &lt;value-of select="id('download-count')"/&gt;
        &lt;text&gt; Fx downloads&lt;/text&gt;
      &lt;/template&gt;
    &lt;/transform&gt;
  &lt;/template&gt;
  &lt;pages&gt;
    <b>&lt;include&gt;<span class="plain">http://(www\.)?spreadfirefox\.com/(index\.php)?</span>&lt;/include&gt;</b>
  &lt;/pages&gt;
&lt;/generator&gt;
</pre>
<p>If you're unfamiliar with regular expressions, see <a href="en/Creating_regular_expressions_for_a_microsummary_generator">Creating regular expressions for a microsummary generator</a> for a tutorial on writing them.
</p>
<h2 name="Making_the_Generator_Available_for_Download"> Making the Generator Available for Download </h2>
<p>Now that the generator applies to the Spread Firefox home page, the only thing left to do is to make it downloadable.  To do so, we need to put it up on the web and then create a JavaScript link on some web page that calls Firefox's <cite>window.sidebar.addMicrosummaryGenerator()</cite> method to download and install the generator.
</p><p>For example, if we put the generator file on the web at http://people.mozilla.com/~myk/microsummaries/tutorial/sfx-generator.xml, and we wanted users to be able to install it from http://people.mozilla.com/~myk/microsummaries/tutorial/index.html, we might add the following code to the <cite>index.html</cite> page:
</p>
<pre class="eval"><b>&lt;a href="javascript:window.sidebar.addMicrosummaryGenerator('<span class="plain">http://people.mozilla.com/~myk/microsummaries/tutorial/sfx-generator.xml</span>')"&gt;Install the Spread Firefox home page microsummary!&lt;/a&gt;</b>
</pre>
<p>Clicking that link will generate a JavaScript error on browsers that don't support microsummaries, however, so to improve the experience for those users, we should check to see if the user is using a microsummaries-enabled browser and display an explanatory message if not.  We might do so via the following code:
</p>
<pre class="eval"><b>&lt;script&gt;</b>
<b>  const warning = "Sorry, you need a microsummary-enabled browser like Firefox 2.0 to install and use microsummary generators.";</b>
<b>  function addGenerator(url) {</b>
<b>    if (typeof window.sidebar == "object" &amp;&amp;</b>
<b>        typeof window.sidebar.addMicrosummaryGenerator == "function")</b>
<b>      window.sidebar.addMicrosummaryGenerator(url);</b>
<b>    else</b>
<b>     alert(warning);</b>
<b>  }</b>
<b>&lt;/script&gt;</b>
<b>&lt;a href="javascript:addGenerator('<span class="plain">http://people.mozilla.com/~myk/microsummaries/tutorial/sfx-generator.xml</span>')"&gt;Install the Spread Firefox home page microsummary!&lt;/a&gt;</b>
</pre>
<p>Note that due to {{template.Bug(341283)}}, <cite>addMicrosummaryGenerator()</cite> will not accept a relative URL.
</p>
<h2 name="Conclusion"> Conclusion </h2>
<p>You should now have a microsummary generator that displays the current Firefox download count when you install it, bookmark the Spread Firefox home page, and select the microsummary from the <cite>Summary</cite> drop-down menu in the <cite>Add Bookmark</cite> dialog.
</p><p>For more information about Microsummaries, see the <a class="external" href="http://wiki.mozilla.org/Microsummaries">Microsummaries home page</a>.
</p>{{ wiki.languages( { "ca": "ca/Creaci\u00f3_d\'un_microsumari", "fr": "fr/Cr\u00e9ation_d\'un_micror\u00e9sum\u00e9", "it": "it/Creare_un_Microsommario", "pl": "pl/Tworzenie_mikropodsumowania", "ja": "ja/Creating_a_Microsummary" } ) }}
Revert to this revision