diff options
author | snaka | 2009-07-28 18:23:29 +0000 |
---|---|---|
committer | snaka | 2009-07-28 18:23:29 +0000 |
commit | 0ccc3d36d09507b3d9ccde58307c8bf814571c82 (patch) | |
tree | bf936d73c9c88e2877b561f785d4c20a4254075b | |
parent | 7bb5779f3b1f222572512a48379cac365f88b792 (diff) | |
download | vimperator-plugins-0ccc3d36d09507b3d9ccde58307c8bf814571c82.tar.bz2 |
refactoring#2
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@34668 d0d07461-0603-4401-acd4-de1884942a52
-rw-r--r-- | hateDAopener.js | 83 |
1 files changed, 40 insertions, 43 deletions
diff --git a/hateDAopener.js b/hateDAopener.js index 4f1b330..de5c6ea 100644 --- a/hateDAopener.js +++ b/hateDAopener.js @@ -86,7 +86,6 @@ let PLUGIN_INFO = // }}} plugins.hateDAopener = (function(){ - let libly = liberator.plugins.libly; // PUBLIC ///////////////////////////////////////////////////////////////{{{ let self = { extractTitleAndTags: extractTitleAndTags, @@ -100,18 +99,26 @@ plugins.hateDAopener = (function(){ ["hatedaopen", "ho"], "Hatena::Diary opener", function(args, bang) { + if (!args.string || args.string == '') + return; liberator.open(args.string, liberator.CURRENT_TAB); }, { completer: function(context, args) { - context.format = { - anchored: false, - title: ["Title and URL", "Tags"], - keys: { text: "url", baseUrl: "baseUrl", path: "path", name: "name", tags: "tags"}, - process: [templateTitleAndUrl, templateTags] - }; - context.filterFunc = null; - context.regenerate = true; - context.generate = function() filteredCandidates(args); + context.format = { + anchored: false, + title: ["Title and URL", "Tags"], + keys: { + text: "url", + baseUrl:"baseUrl", + path: "path", + name: "name", + tags: "tags" + }, + process: [templateTitleAndUrl, templateTags] + }; + context.filterFunc = null; + context.regenerate = true; + context.generate = function() filteredCandidates(args); }, argCount: "*", bang: true, @@ -123,11 +130,9 @@ plugins.hateDAopener = (function(){ // PRIVATE //////////////////////////////////////////////////////////////{{{ /** + * get accounts * @return accounts info - * ex. - * [['snaka72', 'd'], - * ['Snaka', 'd'], - * ['snaka72', 'vimperator.g']] + * ex. [['snaka72', 'd'], ['snaka72', 'vimperator.g'], ...] */ function accounts() liberator.globalVariables.hateDAopener_accounts || []; @@ -143,9 +148,6 @@ plugins.hateDAopener = (function(){ ); } - function hatenaDiaryUrl(diary, userId) - 'http://' + diary + '.hatena.ne.jp/' + userId; - /** * Get candidates list * @return [{"url": "(url)", "name": "hogehoge", "tags": "[hoge]"}, ... ] @@ -188,33 +190,36 @@ plugins.hateDAopener = (function(){ }; })(); + function hatenaDiaryUrl(diary, userId) + 'http://' + diary + '.hatena.ne.jp/' + userId; + /** * @param String Title and Tags ex. "[hoge, fuga]About me." * @return [String title, [String tags, ...]] */ - function extractTitleAndTags(titleAndTag) { - let patternTags = /\[[^\]]+\]/g; - return [ + function extractTitleAndTags(titleAndTag) + let (patternTags = /\[[^\]]+\]/g) [ titleAndTag.replace(patternTags, ''), (titleAndTag.match(patternTags) || []) ]; - } - function templateTitleAndUrl(item){ - let simpleURL = item.text.replace(/^https?:\/\//, ''); - let favicon = getFaviconURI(item.baseUrl + '/'); - return <> - <img src={favicon} /> - <span class="td-strut"/>{item.name} - <a href={item.text} highlight="simpleURL"> - <span class="extra-info">{simpleURL}</span> - </a> - </>; - } + /** + * template: title & url + */ + function templateTitleAndUrl(item) + <> + <img src={getFaviconURI(item.baseUrl + '/')} /> + <span class="td-strut"/>{item.name} + <a href={item.text} highlight="simpleURL"> + <span class="extra-info">{item.text.replace(/^https?:\/\//, '')}</span> + </a> + </>; - function templateTags(item){ - return item.tags && item.tags.length > 0 ? item.tags.join("") : ""; - } + /** + * template: tags + */ + function templateTags(item) + item.tags && item.tags.length > 0 ? item.tags.join("") : ""; let getFaviconURI = (function() { let faviconCache = {}; @@ -233,17 +238,9 @@ plugins.hateDAopener = (function(){ } })(); - // }}} - // UTILITY //////////////////////////////////////////////////////////////{{{ function dump(title, obj) liberator.dump(title + "\n" + util.objectToString(obj)); - function rns(source) - source.split(/\r?\n/); - - function csv(source) - source.split(","); - // }}} return self; })(); |