http://martin.krogmann.info

Ubiquity Script for Timing

written on Jan. 12, 2010, 1:35 p.m. by Martin Krogmann. Tags: code firefox ubiquity time
A Ubiquity (Firefox) script that shows a reminder after a user specified time.

With the Ubiquity extension for Firefox, the browser becomes easily scriptable. The following script adds the keyword time. The user enters a time in seconds/minutes/hours and a notification is shown, when the specified time has elapsed.

 Here is the (unfinished) code:


/* This is command allows the user to enable a reminder after a specified period of time.. */
CmdUtils.CreateCommand({
  names: ["time"],
  icon: "http://www.mozilla.com/favicon.ico",
  description: "A timer utility.",
  help: "time [timeInSeconds] <(optional) unit from {s, m, h}>",
  author: {name: "Martin Krogmann", email: "martin{/at/}krogmann.info"},
  license: "MIT",
  homepage: "http://martin.krogmann.info/",
  arguments: [{role: 'object', nountype: noun_type_number}, {role: 'object', nountype: noun_arb_text}],
  parseArgs: function parseArgs(args) {
    CmdUtils.log("args: " + args);
 //   CmdUtils.log("args.timeValue: " + args.timeValue.text);
 //   CmdUtils.log("args.timeUnit: " + args.timeUnit.text);
    this.time = parseInt(args.object.text);
    this.unit = "seconds";
    this.timeInSecs = this.time;
    if(args.timeUnit != null) {
       var token = args.object.text;
       if(token == "s") {
         this.timeInSecs = this.time;
       } else if(token == "m") {
         this.unit = "minutes";
         this.timeInSecs = 60*this.time;
       } else if(token == "h") {
         this.unit = "hours";
         this.timeInSecs = 60*60*this.time;
       }
    }
    if(this.time.length == 0) {
      this.time = "?";
//      CmdUtils.log("Setting time to '?': " + this.time);
    }
  },
  preview: function preview(pblock, args) {
    var argsObj = new this.parseArgs(args);
    pblock.innerHTML = "Start timer with " + argsObj.time + " " + argsObj.unit + ".";
  },

  execute: function execute(args) {
    var argsObj = new this.parseArgs(args);
    displayMessage("Timer set to: " + argsObj.time + " " + argsObj.unit, this);
    
    var timeIsOut = function timeIsOut() {
      displayMessage("The specified time of " + argsObj.time + " " + argsObj.unit + " has passed!", this);
    };
//    CmdUtils.log("Timer set to: " + argsObj.time);
    Utils.setTimeout(timeIsOut, argsObj.timeInSecs*1000);
  }
});
Thanks for visiting this site.