1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
/** * ==VimperatorPlugin== * @name bufferecho.js * @description Display results of JavaScript to a buffer(browser) instead of commandline-buffer * @description-ja JavaScript実行結果をコマンドライン・バッファではなくバッファ(ブラウザ)に表示 * @version 0.1 * ==/VimperatorPlugin== */ liberator.plugins.buffer_echo = (function(){ var title = "bufferecho results"; var prefix = 'data:text/html,'; function execute(str){ var result; try { result = (function(){ return window.eval("with(liberator) {" + str + "}") })(); } catch (e) { result = e.name + ":\n" + e.message; } return result; } function htmlEscape(str){ return str.replace("&","&","g") .replace("<","<","g") .replace(">",">","g"); } commands.addUserCommand(['bufferecho','becho'],'Display results of JavaScript to a buffer(browser)', function(args, special){ liberator.plugins.buffer_echo.open(args, special); },{ completer: function(filter) completion.javascript(filter) },true ); var manager = { append: function(htmlString){ var body = buffer.evaluateXPath('/html/body').snapshotItem(0); body.innerHTML += htmlString; }, open: function(str, forceNewTab) { var result = execute(str); if (typeof(result) == "object") result = util.objectToString(result,true); var data = '
' + result + '