| 1 | /* |
|---|
| 2 | * http://www.bijint.com/ |
|---|
| 3 | * |
|---|
| 4 | * == Start == |
|---|
| 5 | * js plugins.bijin_clock.start(min) |
|---|
| 6 | * min: interval minutes (default: 1) |
|---|
| 7 | * |
|---|
| 8 | * == Stop == |
|---|
| 9 | * js plugins.bijin_clock.stop() |
|---|
| 10 | */ |
|---|
| 11 | let PLUGIN_INFO = |
|---|
| 12 | <VimperatorPlugin> |
|---|
| 13 | <name>{NAME}</name> |
|---|
| 14 | <description>Bijin Clock - http://www.bijint.com</description> |
|---|
| 15 | <version>0.1</version> |
|---|
| 16 | </VimperatorPlugin>; |
|---|
| 17 | |
|---|
| 18 | liberator.plugins.bijin_clock = (function(){ |
|---|
| 19 | const BASE_URL = 'http://www.bijint.com/jp/img/photo/'; |
|---|
| 20 | const TITLE = fromUTF8Octets("美人時計"); |
|---|
| 21 | const NAME = "Bijin Clock"; |
|---|
| 22 | let interval = null; |
|---|
| 23 | function getTimeString(date){ |
|---|
| 24 | let time = date.toTimeString(); |
|---|
| 25 | return time.substr(0,2) + time.substr(3,2); |
|---|
| 26 | } |
|---|
| 27 | function fromUTF8Octets(octets){ |
|---|
| 28 | return decodeURIComponent(octets.replace(/[%\x80-\xFF]/g, function(c){ |
|---|
| 29 | return '%' + c.charCodeAt(0).toString(16); |
|---|
| 30 | })); |
|---|
| 31 | } |
|---|
| 32 | function showBijinClock(){ |
|---|
| 33 | let date = new Date; |
|---|
| 34 | let image_src = BASE_URL + getTimeString(date) + ".jpg"; |
|---|
| 35 | liberator.echomsg(date.toLocaleString(), 0); |
|---|
| 36 | openDialog('data:application/vnd.mozilla.xul+xml;charset=utf-8,' + |
|---|
| 37 | <><?xml-stylesheet type="text/css" href="chrome://global/skin/"?> |
|---|
| 38 | <?xml-stylesheet type="text/css" href="chrome://browser/skin/browser.css"?> |
|---|
| 39 | <window title={TITLE} |
|---|
| 40 | windowtype="alert:clock" |
|---|
| 41 | style="background-color:transparent;" |
|---|
| 42 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|---|
| 43 | <script type="application/javascript"><![CDATA[ |
|---|
| 44 | var image; |
|---|
| 45 | var interval; |
|---|
| 46 | var opacity = 1; |
|---|
| 47 | function init(){ |
|---|
| 48 | image = document.getElementById('contents'); |
|---|
| 49 | var x = screen.availLeft + screen.availWidth - outerWidth; |
|---|
| 50 | var y = screen.availTop + screen.availHeight - outerHeight; |
|---|
| 51 | window.moveTo(x, y); |
|---|
| 52 | image.style.backgroundColor = "-moz-dialog"; |
|---|
| 53 | setTimeout(function(){ |
|---|
| 54 | interval = window.setInterval(setOpacity, 200); |
|---|
| 55 | }, 5 * 1000); |
|---|
| 56 | } |
|---|
| 57 | function setOpacity(){ |
|---|
| 58 | if (opacity < 0.2){ |
|---|
| 59 | stopAndClose(); |
|---|
| 60 | } |
|---|
| 61 | opacity -= 0.1; |
|---|
| 62 | image.style.opacity = opacity; |
|---|
| 63 | } |
|---|
| 64 | function stopAndClose(){ |
|---|
| 65 | clearInterval(interval); |
|---|
| 66 | window.close(); |
|---|
| 67 | } |
|---|
| 68 | ]]></script> |
|---|
| 69 | <vbox id="contents" flex="1" |
|---|
| 70 | style="border:thin solid black;"> |
|---|
| 71 | <hbox flex="1"> |
|---|
| 72 | <label value={TITLE + "-" + date.toLocaleString()} flex="1"/> |
|---|
| 73 | <toolbarbutton label="X" oncommand="stopAndClose()" style="padding:0;margin:0;"/> |
|---|
| 74 | </hbox> |
|---|
| 75 | <image id="img" src={image_src} onload="init()" onerror="window.close()"/> |
|---|
| 76 | </vbox> |
|---|
| 77 | </window></>.toXMLString(), |
|---|
| 78 | TITLE, |
|---|
| 79 | 'chrome,dialog=yes,titlebar=no,popup=yes'); |
|---|
| 80 | } |
|---|
| 81 | let self = { |
|---|
| 82 | start: function(){ |
|---|
| 83 | showBijinClock(); |
|---|
| 84 | if (interval) this.stop(); |
|---|
| 85 | interval = window.setInterval(showBijinClock, 60 * 1000); |
|---|
| 86 | return interval; |
|---|
| 87 | }, |
|---|
| 88 | stop: function(){ |
|---|
| 89 | if (interval){ |
|---|
| 90 | window.clearInterval(interval); |
|---|
| 91 | } |
|---|
| 92 | let w = Cc["@mozilla.org/appshell/window-mediator;1"] |
|---|
| 93 | .getService(Ci.nsIWindowMediator) |
|---|
| 94 | .getMostRecentWindow("alert:clock") |
|---|
| 95 | if (w) w.close(); |
|---|
| 96 | }, |
|---|
| 97 | }; |
|---|
| 98 | setTimeout(function(){showBijinClock();}, 0); |
|---|
| 99 | setTimeout(function(){self.start();}, 60 * 1000 - Date.now() % (60*1000)); |
|---|
| 100 | |
|---|
| 101 | return self; |
|---|
| 102 | })(); |
|---|
| 103 | // vim:sw=2 ts=2 et: |
|---|