diff options
author | anekos | 2008-12-02 12:00:46 +0000 |
---|---|---|
committer | anekos | 2008-12-02 12:00:46 +0000 |
commit | eae4fae848458cfd438f7746c302f877e03ebec1 (patch) | |
tree | 709f20e4e2402cab5f6276861bc166b5b003559e | |
parent | 0b31bf8554ad77b86fcbdfa13b40f5c0301cadec (diff) | |
download | vimperator-plugins-eae4fae848458cfd438f7746c302f877e03ebec1.tar.bz2 |
Initial release: ステータスラインに情報を表示
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@25705 d0d07461-0603-4401-acd4-de1884942a52
-rw-r--r-- | statstat.js | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/statstat.js b/statstat.js new file mode 100644 index 0000000..c768613 --- /dev/null +++ b/statstat.js @@ -0,0 +1,105 @@ +// ==VimperatorPlugin== +// @name Stat Stat +// @description Show information on statusline. +// @description-ja $B%9%F!<%?%9%i%$%s$K>pJs$rI=<((B +// @license Creative Commons Attribution-Share Alike 3.0 Unported +// @version 1.0 +// @author anekos (anekos@snca.net) +// @minVersion 2.0pre +// @maxVersion 2.0pre +// ==/VimperatorPlugin== +// +// Usage: +// :statstat <JS_EXPRESSION> +// +// Usage-ja: +// :statstat <JS_EXPRESSION> +// +// Links: +// http://d.hatena.ne.jp/nokturnalmortum/20081202/1228218135 +// License: +// http://creativecommons.org/licenses/by-sa/3.0/ + + +(function () { + + let stat = liberator.plugins.statstat; + let defaultExpression = liberator.globalVariables.statstat_expression; + let defaultInterval = liberator.globalVariables.statstat_interval; + let autorun = s2b(liberator.globalVariables.statstat_autorun, false); + + function s2b (s, d) (!/^(\d+|false)$/i.test(s)|parseInt(s)|!!d*2)&1<<!s; + function e2a (e) function () liberator.eval(e); + + // Initialize + if (stat) { + let e = stat.panel; + if (e && e.parentNode) + e.parentNode.removeChild(e); + if (stat.handle) { + clearInterval(stat.handle); + stat.handle = null; + } + } + + { + let panel = this.panel = document.createElement('statusbarpanel'); + panel.setAttribute('id', 'ank-stat-stat-panel'); + let label = document.createElement('label'); + label.setAttribute('value', '-----'); + panel.appendChild(label); + let stbar = document.getElementById('status-bar'); + stbar.insertBefore(panel, document.getElementById('liberator-statusline').nextSibling); + + stat = liberator.plugins.statstat = { + panel: panel, + label: label, + interval: 1000, + set text (value) this.label.setAttribute('value', '<- ' + value + ' ->'), + action: function () new Date().toLocaleString(), + execute: function () (this.text = this.action.apply(this, arguments)), + run: function () { + let self = this; + Array.slice(arguments).forEach(function (v) { + if (v instanceof Function) + self.action = v; + else if (typeof v == 'string') + self.action = function () liberator.eval(v); + else if (typeof v == 'number') + self.interval = v; + }); + this.handle = setInterval(function () self.execute(), this.interval); + }, + handle: null + }; + } + + // set default + if (defaultExpression) + stat.action = e2a(defaultExpression); + if (defaultInterval) + stat.interval = parseInt(defaultInterval); + if (autorun) + stat.run(); + + commands.addUserCommand( + ['statstat'], + 'Run statstat', + function (arg, bang, count) { + if (stat.handle) + clearInterval(stat.handle); + let interval = count ? count * 100 : 100; + stat.action = e2a(arg.string); + stat.handle = setInterval(function () stat.execute(), interval); + }, + { + completer: function (context) completion.javascript(context), + argCount: '*', + count: true + }, + true + ); + +})(); + +// vim:sw=2 ts=2 et si fdm=marker: |