Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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
You can’t perform that action at this time.