Ubiquity und Microformats

Ubiquity bietet (neben Operator) endlich einen echten Anwendungsfall für die Microformats Firefox API. Die Microformats API basiert auf JavaScript und lässt sich somit auch direkt (und ohne viel Aufwand) in die Ubiquity-Commands integrieren.

Das folgende wirklich sinnvolle Beispiel zählt alle hCards einer Seite und gibt das Ergebnis als System-Message aus:

Components.utils.import("resource://gre/modules/Microformats.js");
CmdUtils.CreateCommand({
  name: "count-hcards",
  execute: function() {
    var doc = Application.activeWindow.activeTab.document;	
    var uFcount = Microformats.count('hCard', doc);
    displayMessage( uFcount );
  }
})Code-Sprache: JavaScript (javascript)

Martin McEvoy hat ein paar wesentlich schickere Commands gebaut, die mit Hilfe des Transformrs Mikroformate verarbeitet. Da für diese Verarbeitung ein Redirect (oder das öffnen einer zweiten Seite) notwendig ist, überprüft er mit Hilfe der Microformats-API zuerst ob sich die notwendigen Mikroformate überhaupt auf der Seite befinden.

Der folgende Code (von Martin) testet z.B. ob mind. ein hCalendar verfügbar ist, bevor er diesen verarbeitet:

CmdUtils.CreateCommand({
  icon: "http://transformr.co.uk/favicon.ico",
  name: "get-webcal",
  author: {name: "Martin McEvoy", email: "weborganics@googlemail.com"},
  help: "Subscribe to a webcal feed using the 
<a href=\"http://microformats.org/wiki/hcalendar\">hCalendar</a> Microformat.",
  preview: function ( pblock ) {
    pblock.innerHTML = "Subscribe to web calendar";
  },
  execute: function() {
    var doc = Application.activeWindow.activeTab.document;
    var mFcount = Microformats.count('hCalendar', doc,{ showHidden : true });
    if (mFcount > 0) {
      var url = "webcal://transformr.co.uk/hcalendar/";
      url += CmdUtils.getWindowInsecure().location ; 
      Utils.openUrlInBrowser(url);
    } else {
      displayMessage('Sorry No hCalendar Events Found!');
    }
  }
})Code-Sprache: PHP (php)

Quelle: http://transformr.co.uk/commands

Weitere großartige Ubiquity-Commands im Microfromats-Wiki…

Matthias Pfefferle
Matthias Pfefferle
@pfefferle@notiz.blog

Ich bin Webworker und arbeite als „Open Web Lead“ @ Automattic. Ich blogge, podcaste und schreibe eine Kolumne über das open, independent und federated social Web. Mehr über mich.

772 Beiträge
851 Folgende
Fediverse Reactions

Ein Kommentar

  1. Good Post Matthias thank you for your ideas 😉

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Your post must include a link to this post.

How does this work?
Write a response on your own website and include a link to this post. Then submit your response’s URL here. Your response may appear here after moderation. To update or remove it, edit or delete your original post and submit the same URL again. Learn more about Webmentions.