Skip to content

Instantly share code, notes, and snippets.

@xrogaan xrogaan/synonym.js
Created Apr 17, 2009

Embed
What would you like to do?
Ubiquity command to search for french synonyms at www.cnrtl.fr
function getSynonymie(previewBlock, word) {
var searchUrl = "http://www.cnrtl.fr/synonymie/";
CmdUtils.previewAjax(previewBlock, {
type: "GET",
url: searchUrl + word,
error: function() {
previewBlock.innerHTML = "<i>Error retreiving synonyms list.</i>";
},
success: function(responseData) {
var syn = "<ol>";
var resultSummary = jQuery(responseData).find(".syno_format").each(function(i) {
var synonyme = jQuery(this).text();
var synTemp = "<li><a href=\"" + searchUrl + synonyme + "\">" + synonyme + "</a></li>";
syn += synTemp;
});
syn += "</ol>";
var previewTemplate = "<span class=\"wikisummary\">${summary}</span>";
var previewData = {
summary: syn
};
previewBlock.innerHTML += CmdUtils.renderTemplate(previewTemplate,previewData);
}
});
}
CmdUtils.CreateCommand({
name: ['synonyme'],
arguments: [ {role: 'object', nountype: noun_arb_text, label: 'query'} ],
icon: "http://www.cnrtl.fr/favicon.ico",
author: {name: "Bellière Ludovic", email: "xrogaan@gmail.com", homepage: "http://www.xrogaan.be/"},
license: "GPL",
description: "Search for french synonyms at www.cnrtl.fr",
help: "Select a word",
preview: function(pblock, args) {
var data = {};
data.query = args.object.text;
if (data.query.length <= 0) {
pblock.innerHTML = "Recherche de synonymes."
return;
}
pblock.innerHTML = CmdUtils.renderTemplate("Recherche des synonymes de <b>${query}</b>.", data);
getSynonymie(pblock,data.query);
},
execute: function(args) {
var data = {};
data.query = args.object.text;
if (data.query.length < 1) {
displayMessage("Veuillez taper un mot...");
return;
}
Utils.openUrlInBrowser("http://www.cnrtl.fr/synonymie/" + data.query);
}
});
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.