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.

767 Beiträge
816 Folgende
Fediverse Reactions

Ein Kommentar zu „Ubiquity und Microformats“

  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

To respond on your own website, enter the URL of your response which should contain a link to this post’s permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post’s URL again. (Find out more about Webmentions.)