Skip to content

Instantly share code, notes, and snippets.

@satyr
Created September 6, 2008 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satyr/9130 to your computer and use it in GitHub Desktop.
Save satyr/9130 to your computer and use it in GitHub Desktop.
[Ubiquity] thesaurus.com
+function(pq){
const Thesaurus = 'http://thesaurus.reference.com/';
CmdUtils.CreateCommand({
name: "thesaurus",
icon: Thesaurus +'favicon.ico',
takes: {word: noun_arb_text},
description: ''+<>Consults <a href={Thesaurus}>thesaurus.com</a>.</>,
execute: function({text}){
Utils.openUrlInBrowser(makeReq(jQuery.trim(text)));
},
preview: function(pbl, {text}){
var q = jQuery.trim(text), $p = jQuery(pbl), $c = $p.find(ID);
if(!$c[0]) $c = $p.html(Base).find(ID), pq = '';
if(!q || pq === (pq = q)) return;
$c.removeClass().addClass('loading').empty();
CmdUtils.previewAjax(pbl, {
url: makeReq(q),
success: function(htm){ setTables($c.removeClass(), htm) },
error: function(x, e){
error($c, x.status +' '+ x.statusText +' / '+ e) }});
},
author: 'satyr'.link('http://d.hatena.ne.jp/murky-satyr'), license: 'MIT'
});{}
function error($c, msg){ $c.addClass('error').text(msg) }
function makeReq(word)
'http://thesaurus.reference.com/search?q='+ encodeURIComponent(word);
function setTables($c, htm){
var m = htm.match(/<table\b[^>]*?\bclass="the_content"[\s\S]+?\/table>/g);
m ? $c.html(m.join('')) : error($c, 'No matches.');
}
const
ID = '#_'+(Math.random()+'').slice(2),
Base = <div class="thesaurus"><style><![CDATA[
@table {border-collapse:separate; border-spacing:0px}
@td {font-size:88%; padding-right:4px}
@.error {font-style:oblique}
@table, @.error {padding-bottom:4px}
@.logo {display:block}
@.loading + .logo {opacity:0.5}
]]></style><div id={ID.slice(1)}/><a class="logo" href={Thesaurus}
><img height="43" border="0" style="background-color:#f4a50a"
src="http://sp.ask.com/en/i/dictionary/thesaurus_logo.gif"/></a
></div>.toXMLString().replace(/@/g, '.thesaurus ');
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment