diff options
author | anekos | 2014-06-20 23:34:30 +0900 |
---|---|---|
committer | anekos | 2014-06-20 23:34:30 +0900 |
commit | 3e79adadc38edc50e92323cbb1cfc85d171e9e1f (patch) | |
tree | 5a6884d12b809785ca1a19d81b624395a07f8e96 | |
parent | c86f88439cf75ce1efa5452542a924623c7b679e (diff) | |
parent | 0c00790b53cefe9103c96eaca921ebd68c668f79 (diff) | |
download | vimperator-plugins-3e79adadc38edc50e92323cbb1cfc85d171e9e1f.tar.bz2 |
Merge pull request #61 from elzzup/alert-absolute
alert.js: 「13:30」などのフォーマットで指定することで時刻を指定出来るようにしました
-rw-r--r-- | alert.js | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -349,6 +349,15 @@ let PLUGIN_INFO = xml` }; } + function torelativetime(h, m) { + if (m > 59) + return false; + h %= 24; + var now = new Date(); + var d = (h * 60 + parseInt(m)) - (now.getHours() * 60 + now.getMinutes() + now.getSeconds() / 60); + return d >= 0 ? d : d + 60 * 24; + } + let alertMethods = { alert: function (next, msg) { window.alert(msg); @@ -436,11 +445,13 @@ let PLUGIN_INFO = xml` function (args) { let methods = [], time = null, message = ''; args.forEach(function (v) { - let m, f; + let m, f, t; if ((m = v.match(/^-(\w+)(?:=(.*))?$/)) && (f = alertMethods[m[1]])) methods.push([f, m[2]]); else if (!time && v.match(/^\d+(\.\d+)?$/)) time = parseFloat(v); + else if (!time && (m = v.match(/^(\d{1,2}):(\d{1,2})$/)) && (t = torelativetime(m[1], m[2]))) + time = parseFloat(t); else message += ' ' + v; }); |