Created
September 3, 2008 12:02
-
-
Save satyr/8575 to your computer and use it in GitHub Desktop.
[Ubiquity] ホッテントリ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Name = 'hotentry', | |
Hatebu = 'http://b.hatena.ne.jp/', | |
Hotent = Hatebu +'hotentry', | |
HTML = <div class={Name}><style><![CDATA[ | |
@ol {list-style:none; margin:0; padding:0} | |
@ol a {text-decoration:none} | |
@.selected {text-decoration:underline} | |
@kbd {font:bold 108% "Consolas", monospace; text-transform:uppercase} | |
@a img {border:none} | |
@.loading + .logo {opacity:0.4} | |
]]></style><ol class="loading" | |
id={Name}></ol><a class="logo" href={Hotent}><img | |
src={Hatebu +'images/logo1.gif'}/><img | |
src={Hatebu +'images/logo2.gif'}/></a></div | |
>.toXMLString().replace(/@/g, '.'+ Name +' ').replace(/>\s+</g, '><'); | |
var ents, last; | |
function keygen(n) n < 36 ? n.toString(36) : '-^@;:[],./\\<>?_'[n - 36]; | |
CmdUtils.CreateCommand({ | |
name: Name, | |
icon: Hatebu +'favicon.ico', | |
takes: {'entry numbers': {_name:'-', | |
default: function()({data: '0', summary: 0}), | |
suggest: function(txt, htm, cb, sx){ | |
if(sx) return []; | |
var m = txt.match(/[0-9a-z\-^@;:\[\],./\\<>?_]/ig) || [0]; | |
return [{summary: m.join(' '), | |
data: m.reduce(function(d, k) d[k] = d, {})}]; | |
}}}, | |
description: 'hotentry'.link(Hotent), | |
help: '"hotentry 012" will open the top 3 entries.', | |
execute: function({data}){ | |
if(ents) for(var n in data) | |
ents[n] && Utils.openUrlInBrowser(ents[n].lnk); | |
}, | |
preview: function(pbl, {data}){ | |
var $l = jQuery('#'+ Name, pbl), now = Date.now(); | |
if(!$l[0]) $l = jQuery(pbl).html(HTML).find('#'+ Name); | |
$l.find('li').each(function(i){ | |
this.className = data[keygen(i)] ? 'selected' : '' }); | |
if(now - last < 5 * 6e4) return; | |
last = now; | |
$l.addClass('loading'); | |
jQuery.get(Hotent +'/diary/rss', function(xml){ | |
ents = {}; | |
jQuery('item', xml).each(function(i){ | |
ents[keygen(i)] = { | |
ttl: jQuery('title', this).text(), | |
lnk: jQuery('link', this).text() }}); | |
$l.removeClass().html( | |
[<li><kbd>{key}</kbd><a href={lnk} accesskey={key}>{ttl}</a></li> | |
for([key, {ttl, lnk}] in Iterator(ents))].join('')); | |
}, 'xml'); | |
}, | |
previewDelay: 42, | |
author: 'satyr'.link('http://d.hatena.ne.jp/murky-satyr'), license: 'MIT', | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment