Skip to content

Instantly share code, notes, and snippets.

@theorm
Created May 29, 2009 10:08
Show Gist options
  • Save theorm/119878 to your computer and use it in GitHub Desktop.
Save theorm/119878 to your computer and use it in GitHub Desktop.
LDOCE online ubiquity command
const ENTRY_TEMPLATE = "<div style=\"clear: both;\"><b><u><a href=\"${link}\">${word} (${type})</a></u></b><br/>" +"</div><br/>";
var $j = jQuery;
CmdUtils.CreateCommand({
name: "ldoce",
icon: "http://www.ldoceonline.com/favicon.ico",
homepage: "http://www.ldoceonline.com/",
author: {name: "Roman Kalyakin", email: "roman.kalyakin@gmail.com"},
license: "GPL",
description: "Show definition of a word from the Longman Dictonary of Contemporary English.",
help: "Type 'ldoce' followed by a word.",
takes: {"input": /.*/},
preview: function(pblock, input) {
if (input.text.length < 1) {
pblock.innerHTML = "Definition from the <b>LDOCE</b>.";
return;
}
pblock.innerHTML = input.text + " is...<br/>";
var url = "http://www.ldoceonline.com/popup/popupmode.html";
var params = {
search_str : input.text
};
CmdUtils.previewGet(pblock,url,params, function(data){
var entry_frame = "http://www.ldoceonline.com" + $j("iframe#entryFrame", data).attr("src");
var result_frame = "http://www.ldoceonline.com" + $j("iframe#resultFrame", data).attr("src");
//pblock.innerHTML += entry_frame;
CmdUtils.previewGet(pblock, entry_frame, null, function(data) {
//$j("script", data).remove()attr("onclick","alert('hi')");
var head = $j("div.Head", data);
var realimg = "http://www.ldoceonline.com" + $j("img.preview",head).attr("src");
$j("img.preview", head).attr("src", realimg);
$j("img.proncar", head).remove();
pblock.innerHTML += "<div id=\"head\" onclick=\"jQuery('head').toggle();\">" + head.html();
$j("div.Sense", data).each(function(){
var s = $j(this);
$j("img", s).remove();
$j("span.COLLO a", s).attr("style", "color:blue; text-decorations: none;");
//var example = $j("div.EXAMPLE",s).text();
//$j("div.EXAMPLE", s).after("<ul><li>" + example + "</li></ul>").remove();
pblock.innerHTML += s.html();
});
pblock.innerHTML += "</div>";
});
});
},
execute: function(input) {
//displayMessage("You selected: " + input.text);
Utils.openUrlInBrowser( "http://www.ldoceonline.com/popup/popupmode.html?search_str="+input.text);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment