From f120bec568aa158d8b2c5dbb415bd1cbdeb61dcb Mon Sep 17 00:00:00 2001 From: suVene Date: Mon, 26 Jan 2009 02:26:44 +0000 Subject: load wedata, and add options git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@29038 d0d07461-0603-4401-acd4-de1884942a52 --- copy.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 3 deletions(-) (limited to 'copy.js') diff --git a/copy.js b/copy.js index ec848bd..6fb668e 100644 --- a/copy.js +++ b/copy.js @@ -3,12 +3,12 @@ var PLUGIN_INFO = {NAME} enable to copy strings from a template (like CopyURL+) テンプレートから文字列のコピーを可能にします(CopyURL+みたいなもの) -1.1 +2.0 2.0pre http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/copy.js teramako MPL 1.1/GPL 2.0/LGPL 2.1 -0.5 +0.6 || +liberator.globalVariables.copy_use_wedata = false; // false by default +||< +true に設定すると wedata からテンプレートを読込みます。 +>|| +liberator.globalVariables.copy_wedata_include_custom = true; // false by default +||< +custom が設定された wedata を読込みます。 +SandBox でなく、window.eval を利用してオブジェクトする為、 +セキュリティ上の理由で初期設定は false になっています。 +true に設定する場合は、動作を理解したうえ自己責任でご利用ください。 +>|| +liberator.globalVariables.copy_wedata_exclude_labels = [ + 'pathtraqnormalize', +]; +||< +wedata から読込まない label のリストを定義します。 ]]> ; @@ -179,7 +198,7 @@ var exCopyManager = { var isError = false; if (special && arg){ try { - copyString = liberator.eval( arg); + copyString = liberator.eval(arg); switch (typeof copyString){ case 'object': copyString = copyString === null ? 'null' : copyString.toSource(); @@ -218,7 +237,45 @@ var exCopyManager = { } } }; + +if (liberator.globalVariables.copy_use_wedata){ + var excludeLabelsMap = {}; + function loadWedata(){ + if (!liberator.plugins.libly){ + liberator.echomsg("need a _libly.js when use wedata."); + return; + } + + var libly = liberator.plugins.libly; + var logger = libly.$U.getLogger("copy"); + + liberator.globalVariables.copy_templates.forEach(function(item) excludeLabelsMap[item.label] = item.value); + if (liberator.globalVariables.copy_wedata_exclude_labels) + liberator.globalVariables.copy_wedata_exclude_labels.forEach(function(item) excludeLabelsMap[item] = 1); + var wedata = new libly.Wedata("vimp%20copy"); + wedata.getItems(24 * 60 * 60 * 1000, + function(item){ + item = item.data; + if (excludeLabelsMap[item.label]) return; + var custom; + try{ + if (liberator.globalVariables.copy_wedata_include_custom) + custom = window.eval("(" + item.custom + ")"); + } catch (e){ + logger.echoerr(e); + logger.log(item.custom); + return; + } + exCopyManager.add(item.label, item.value, custom, item.map); + } + ); + + } + loadWedata(); +} + return exCopyManager; })(); // vim: set fdm=marker sw=4 ts=4 et: + -- cgit v1.2.3