diff options
author | drry | 2008-04-08 10:13:18 +0000 |
---|---|---|
committer | drry | 2008-04-08 10:13:18 +0000 |
commit | 4febc5d1043c715a28f8d5fc1a4fcc8141067423 (patch) | |
tree | 87d796142ff3f83d7ba5f608c0c660b20703ec6b /commandBookmarklet.js | |
parent | 1f4c3d7cdadb776193c63d296aea7360ab654189 (diff) | |
download | vimperator-plugins-4febc5d1043c715a28f8d5fc1a4fcc8141067423.tar.bz2 |
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
Diffstat (limited to 'commandBookmarklet.js')
-rw-r--r-- | commandBookmarklet.js | 36 |
1 files changed, 21 insertions, 15 deletions
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 <halt.feits@gmail.com> * @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: |