Skip to content

Instantly share code, notes, and snippets.

@edgargoncalves
Created October 27, 2008 01:30
Show Gist options
  • Save edgargoncalves/19991 to your computer and use it in GitHub Desktop.
Save edgargoncalves/19991 to your computer and use it in GitHub Desktop.
// Source code for the Priberam Ubiquity command
// By Edgar Gonçalves.
// Version 0.3
// Sun Jan 24 22:03:05 2010
// Adapted for new layout on the Priberam website (bugfix, preview wasn't working anymore - Thanks, Jorge Afonso).
// Version 0.2
// Sun Jun 28 2009
// Changed to use Parser 2 (requires Ubiquity 0.5 or above)
// syntax changed to receive a word after the command "definir", "obter significado de" and "define no priberam".
// Version 0.1
// Mon Oct 27 2008.
var PRIBERAMUBIQUITY = {
//////////////////////////////
//Public Variables:
//////////////////////////////
priberamUrl: "http://priberam.pt/dlpo/definir_resultados.aspx?pal=",
//////////////////////////////
// Public Methods:
//////////////////////////////
getDefinitionPage: function (word, pblock, renderer) {
Utils.parseRemoteDocument(
PRIBERAMUBIQUITY.priberamUrl + word,
null,
function(document) {
var wordDefinition = jQuery('#ContainerDiv > table > tbody > tr > td div:eq(2) > div:eq(1)', document).html();
if (!wordDefinition || wordDefinition == "" || wordDefinition == "Últimas pesquisas:")
wordDefinition = "Palavra não encontrada!";
renderer("\n" + wordDefinition);
},
function() {
renderer("\nErro na pesquisa da palavra!");
}
);
},
// preview function for Ubiquity:
previewEnteredText: function (pblock, args) {
var word = args.object.text;
var msg = "${definition}";
if (word && word.length > 0) {
PRIBERAMUBIQUITY.getDefinitionPage(word,
pblock,
function (definition) {
var subs = {
word: word,
definition: definition
};
pblock.innerHTML = CmdUtils.renderTemplate( msg, subs );
});
} else {
pblock.innerHTML = "";
}
},
// execution function for Ubiquity:
execute: function (word) {
Utils.openUrlInBrowser(this.priberamUrl + (word || ""));
return null;
}
};
CmdUtils.CreateCommand({
names: ['definir', 'obter significado de', 'definir no priberam'],
homepage: "http://http://sites.google.com/site/edgargoncalves/work/software/ubiquity",
author: {name: "Edgar Gonçalves", email: "edgar.goncalves@gmail.com"},
arguments: [ {role: 'object', nountype: /^[^\n\t\r\v\f]+$/, label: 'palavra'} ],
icon: "http://priberam.pt/favicon.ico",
description:"Pesquisa a definição de uma palavra em <a href='http://priberam.pt/dlpo'>Priberam Online</a>.",
help:"Pesquisa a definição de uma palavra em <a href='http://priberam.pt/dlpo'>Priberam Online</a>.",
preview: PRIBERAMUBIQUITY.previewEnteredText,
execute: function(args) {
PRIBERAMUBIQUITY.execute(args.object.text);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment