Alarm
Buttons
* simple alarm, set with absolute or relative time
display:
* begin time, current time, end time, up counter, down counter
bell:
* sound file C:\WINDOWS\Media\notify.wav
note:
* button uses the help tab to store plain text XUL code
* button uses the code tab to store JavaScript used by the XUL code
Behavior
| Action | Behavior |
|---|---|
| open alarm |
Revisions
Code
/*Code*/ /* absolute examples: const target = "Mar 17 2010 3:30:00 PM"; const target = "2010, 3, 17, 15:30:00"; const target = date(0) + "6:00:00 PM"; *//* today *//* const target = date(1) + "12:30:00 AM"; *//* tomorrow *//* relative examples: const target = [1, 15, 0]; *//* 1 hour, 15 minutes *//* const target = [0, 2, 30]; *//* 2 minutes, 30 seconds *//* */ const target = [0, 0, 10]; function date(increment) { return new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + increment). toDateString() + String.fromCharCode(32); } function load() { function absolute(string) { return new Date(string); } function relative(hour, minute, second) { return new Date(beginTime.getTime() + hour * 3600000 + minute * 60000 + second * 1000); } function clock(string) { return (string.length == 10 ? "0" : "") + string; } function count(t0, t1) { var millisecond = t1.getTime() - t0.getTime(); var hour = Math.floor(millisecond / 3600000); var minute = Math.floor(millisecond %3600000 / 60000); var second = Math.floor(millisecond %3600000 %60000 / 1000); var decimal = Math.floor(millisecond %3600000 %60000 %1000 / 10); if (t0 > t1) { hour = 0; minute = 0; second = 0; decimal = 0; clearInterval(that.tick); delete that.tick; sound.play(ios.newFileURI(file)); close(); } hour = (hour < 10 ? "0" : "") + hour; minute = (minute < 10 ? "0" : "") + minute; second = (second < 10 ? "0" : "") + second; decimal = (decimal < 10 ? "0" : "") + decimal; return hour + ":" + minute + ":" + second + "." + decimal; } var ios = Components.classes["@mozilla.org/network/io-service;1"]. getService(Components.interfaces.nsIIOService); var sound = Components.classes["@mozilla.org/sound;1"]. getService(Components.interfaces.nsISound); var file = Components.classes["@mozilla.org/file/local;1"]. createInstance(Components.interfaces.nsILocalFile); file.initWithPath("C:\\WINDOWS\\Media\\notify.wav"); if (this.tick) { clearInterval(this.tick); delete this.tick; } else { var that = this; var beginTime = new Date(); if (target.constructor == String) { var endTime = absolute(target); } else { var endTime = relative(target[0], target[1], target[2]); } this.tick = setInterval(function() { var currentTime = new Date(); document.getElementById("clock1").value = clock(beginTime.toLocaleTimeString()); document.getElementById("clock2").value = clock(currentTime.toLocaleTimeString()); document.getElementById("clock3").value = clock(endTime.toLocaleTimeString()); document.getElementById("count1").value = count(beginTime, currentTime); document.getElementById("count2").value = count(currentTime, endTime); }, 10); } }
Init
/*Initialization code*/ var codeTab = document.getElementById(this.id).getAttribute("cb-oncommand"); var helpTab = document.getElementById(this.id).getAttribute("Help"); this.leftclick = function(event) { var tag = new Array("<script><!\x5bCDATA\x5b", "\x5d\x5d></script>"); var xml = helpTab.replace("</window>", tag[0] + codeTab + tag[1] + "</window>"); var url = "data:application/vnd.mozilla.xul+xml;text/plain," + xml; var feature = "chrome,centerscreen,width=220,height=220"; window.openDialog(url, "", feature); } this.setAttribute("onclick", "custombuttons.gQuot.mHandler(event, this)"); this.setAttribute("author", "Morat"); this.setAttribute("version", "1.0"); this.setAttribute('homepage', 'http://custombuttons2.com/forum/buttons/-graveyard/alarm.html'); this.setAttribute("dependency", "FF 3.0.*, CB2 3.*"); this.setAttribute("status", "Complete"); this.setAttribute("public", true);
Help
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window title="Alarm" onload="load();" align="center" class="dialog" orient="vertical"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" >
<keyset>
<key keycode="VK_ESCAPE" oncommand="close();" />
</keyset>
<vbox>
<label id="clock1" style="font-family: monospace; font-size: xx-large; font-weight: bold" />
<label id="clock2" style="font-family: monospace; font-size: xx-large; font-weight: bold" />
<label id="clock3" style="font-family: monospace; font-size: xx-large; font-weight: bold" />
<label id="count1" style="font-family: monospace; font-size: xx-large; font-weight: bold" />
<label id="count2" style="font-family: monospace; font-size: xx-large; font-weight: bold" />
<button label="CANCEL" oncommand="load();" style="font-size: x-large; font-weight: bold" />
</vbox>
</window>Details
Custom Buttons² was not found: find out why...
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.15) Gecko/2009101601 Firefox/3.0.15
Posted with the theme Pluralism
