diff --git a/content/io.js b/content/io.js index 819d75f5..c227b9d4 100644 --- a/content/io.js +++ b/content/io.js @@ -188,8 +188,8 @@ liberator.IO = function () //{{{ function () { liberator.echo(liberator.io.getCurrentDirectory()); }, { argCount: "0" }); - // mkv[imperatorrc] or mkm[uttatorrc] - liberator.commands.add(["mk" + EXTENSION_NAME.substr(0, 1) + "[" + EXTENSION_NAME.substr(1) + "rc]"], + // "mkv[imperatorrc]" or "mkm[uttatorrc]" + liberator.commands.add([EXTENSION_NAME.replace(/(.)(.*)/, "mk$1[$2rc]")], "Write current key mappings and changed options to the config file", function (args, special) { diff --git a/content/liberator.js b/content/liberator.js index d8498644..c1029e48 100644 --- a/content/liberator.js +++ b/content/liberator.js @@ -392,50 +392,43 @@ const liberator = (function () //{{{ function (args, special, count) { args = args.string; + let method = args[0] == ":" ? "execute" : "eval"; try { if (count > 1) { - var i = count; + let total = 0; var beforeTime = Date.now(); - liberator.interrupted = false; - if (args && args[0] == ":") + for (let i in liberator.util.rangeInterruptable(0, count, 500)) { - while (i-- && !liberator.interrupted) - liberator.execute(args); - } - else - { - while (i--) - liberator.eval(args); + let now = Date.now(); + liberator[method](args); + total += Date.now() - now; } if (special) return; - var afterTime = Date.now(); - - if ((afterTime - beforeTime) / count >= 100) + if (total / count >= 100) { - var each = ((afterTime - beforeTime) / 1000.0 / count); + var each = (total / 1000.0) / count; var eachUnits = "sec"; } else { - var each = ((afterTime - beforeTime) / count); + var each = total / count; var eachUnits = "msec"; } - if (afterTime - beforeTime >= 100) + if (total >= 100) { - var total = ((afterTime - beforeTime) / 1000.0); + var total = total / 1000.0; var totalUnits = "sec"; } else { - var total = (afterTime - beforeTime); var totalUnits = "msec"; } diff --git a/content/util.js b/content/util.js index 86433d53..a5b6ebe7 100644 --- a/content/util.js +++ b/content/util.js @@ -295,6 +295,23 @@ liberator.util = { //{{{ yield start++; }, + rangeInterruptable: function (start, end, time) + { + let endTime = Date.now() + time; + while (start < end) + { + if (Date.now() > endTime) + { + liberator.interrupted = false; + liberator.threadYield(); + if (liberator.interrupted) + throw new Error("Interrupted"); + endTime = Date.now() + time; + } + yield start++; + } + }, + // same as Firefox's readFromClipboard function, but needed for apps like Thunderbird readFromClipboard: function () {