aboutsummaryrefslogtreecommitdiffstats
path: root/alert.js
diff options
context:
space:
mode:
authorHiroto Takahashi2014-05-07 12:46:34 +0900
committerHiroto Takahashi2014-05-07 12:46:34 +0900
commiteb20651ddfea323e9138a80b9cdf536022791bdf (patch)
treec139543230d4431b52c37ad955d9f66bed45c84e /alert.js
parentc2048181730e1dd258de8311485589fbce50ca59 (diff)
downloadvimperator-plugins-eb20651ddfea323e9138a80b9cdf536022791bdf.tar.bz2
update alert.js add module absolute time setting
Diffstat (limited to 'alert.js')
-rw-r--r--alert.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/alert.js b/alert.js
index 957da6a..6aeabf8 100644
--- a/alert.js
+++ b/alert.js
@@ -349,6 +349,14 @@ let PLUGIN_INFO = xml`
};
}
+ function torelativetime(h, m) {
+ if (h < 0 || h > 24 || m < 0 || m > 59)
+ return false;
+ 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 +444,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;
});