diff options
Diffstat (limited to 'alert.js')
-rw-r--r-- | alert.js | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -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; }); |