Created
December 2, 2008 23:43
-
-
Save satyr/31335 to your computer and use it in GitHub Desktop.
[Ubiquity] tinyurl improved
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 = 'tinyur1', | |
TURL = 'http://tinyurl.com/', | |
Selector = '#'+ Name, | |
Base = <div class={Name}><style><![CDATA[ | |
@.result {text-align:center} | |
@.arrow {font-weight:bold; margin:2px 0} | |
@.error {font-style:italic; margin-bottom:4px} | |
@.logo { | |
background:#009; font:bold 16px sans-serif; width:6.6em; text-align:center} | |
@.logo a {color:#fff; text-decoration:none} | |
@.loading + .logo {opacity:0.4} | |
@.error + .logo {opacity:0.7} | |
]]></style><div id={Name}/><div class="logo" | |
><a href={TURL}>TinyURL.com</a></div></div | |
>.toXMLString().replace(/@/g, '.'+ Name +' '); | |
var tiny, pq; | |
CmdUtils.CreateCommand({ | |
name: Name, | |
synonyms: ['tinyurl'], | |
icon: TURL +'favicon.ico', | |
takes: {URL: noun_type_url}, | |
modifiers: {to: {_name: 'alias', | |
suggest: function(txt, htm, cb, sx) | |
txt && !sx ? [CmdUtils.makeSugg(txt, htm)] : [] }}, | |
description: ''+<> | |
Improved <a href={TURL}>tinyurl</a> that | |
<ul style="list-style-image:none"> | |
<li>supports alias.</li> | |
<li>copies on enter.</li></ul></>, | |
execute: function(){ | |
if(tiny) CmdUtils.copyToClipboard(tiny); | |
else displayMessage({ | |
icon: this.icon, title: 'Error', text: 'No result yet!'}); | |
tiny = ''; | |
}, | |
preview: function(pbl, {text: u}, mod){ | |
var a = mod.to.text || '', $p = jQuery(pbl), $c = $p.find(Selector); | |
if(!$c[0]) $c = $p.html(Base).find(Selector), pq = ''; | |
if(tiny && pq === (pq = u + a)) return; | |
$c.addClass('loading'); | |
Utils.parseRemoteDocument( | |
TURL +'create.php', {url: u, alias: a}, function(doc){ | |
var [org, tin] = ((doc = jQuery(doc)).find('blockquote > b') | |
.map(function() this.textContent).get()), | |
err = doc.find('p > b[style]').text(); | |
$c.removeClass().addClass(err ? 'error' : '').html( | |
<><i>{err.slice(0, 48)}</i><div class="result" | |
>{org}<div class="arrow">↓</div | |
><a href={tiny = tin}>{tin}</a></div></> +''); | |
}); | |
}, | |
previewDelay: 234, | |
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