diff options
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: |