From 4febc5d1043c715a28f8d5fc1a4fcc8141067423 Mon Sep 17 00:00:00 2001 From: drry Date: Tue, 8 Apr 2008 10:13:18 +0000 Subject: lang/javascript/vimperator-plugins/trunk/commandBookmarklet.js: * crop 基準を文字幅に変更しました。(簡易) * ほか、インデントなど。 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@9134 d0d07461-0603-4401-acd4-de1884942a52 --- commandBookmarklet.js | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'commandBookmarklet.js') diff --git a/commandBookmarklet.js b/commandBookmarklet.js index e279b32..5839b26 100644 --- a/commandBookmarklet.js +++ b/commandBookmarklet.js @@ -1,5 +1,5 @@ /** - * bookmarklet wo command ni suru plugin + * bookmarklet wo command ni suru plugin * * @author halt feits * @version 0.6.0 @@ -16,22 +16,28 @@ liberator.echoerr("No bookmarks set"); } } - - for (var i = 0; i < items.length; i++) { - var title = liberator.util.escapeHTML(items[i][1]); - if (title.length > 50) { - title = title.substr(0, 47) + "..."; + + items.forEach(function(item) { + var [url, title] = item; + if (width(title) > 50) { + while (width(title) > 47) + title = title.slice(0, -1); + title += "..."; } + title = liberator.util.escapeHTML(title); - var url = liberator.util.escapeHTML(items[i][0]); - var command = new Function('', 'liberator.open("' + url + '");'); + url = liberator.util.escapeHTML(url); + var command = new Function("", 'liberator.open("' + url + '");'); liberator.commands.addUserCommand( - [title], - 'bookmarklet', - command, - { - shortHelp: 'bookmarklet', - } + [title], + "bookmarklet", + command, + { + shortHelp: "bookmarklet", + } ); - } + }); + + function width(str) str.replace(/[^\x20-\xFF]/g, " ").length; })(); +// vim:sw=2 ts=2 et: -- cgit v1.2.3