Skip to content

Instantly share code, notes, and snippets.

@dlorych
Created May 30, 2009 18:00
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 dlorych/120581 to your computer and use it in GitHub Desktop.
Save dlorych/120581 to your computer and use it in GitHub Desktop.
filmweb.pl search ubiquity keyword
var mainURL = 'http://www.filmweb.pl';
var searchURL = mainURL + '/szukaj';
function parseSearchResult(htmlResult){
var results = jQuery(htmlResult).find('#searchFixCheck');
var content = "";
// remove style attribute from span elements
results.find("span").each( function(spanIndex, spanItem) {
jQuery(spanItem).removeAttr('style');
});
// update href attributes
results.find("a").each( function(idx, item) {
var value = jQuery(item).attr('href');
jQuery(item).attr('href', mainURL + Utils.trim(value));
});
// preview first 3 results
results.find('li').each( function(liIndex, liItem) {
if(liIndex >= 3) return false;
content += liItem.innerHTML + '<br />';
});
return content;
};
if (CmdUtils.parserVersion == 2) {
CmdUtils.CreateCommand({
names: ['filmweb', 'find movie'],
icon: 'http://gfx.filmweb.pl/gf/favicon.ico',
arguments: [ {role: 'object', nountype: noun_arb_text, label: 'movie title'} ],
author: {name: 'Daniel Lorych', email: 'd.lorych@gmail.com'},
license: 'MPL',
description: 'Seeks <a href="www.filmweb.pl">Filmweb</a> for movies matching your words.',
preview: function(pblock, args){
var movieTitle = jQuery.trim(args.object.text);
if(movieTitle.length < 1){
pblock.innerHTML = 'Seeks filmweb.pl database for <i>movie title</i>.';
return;
}
var previewTemplate = 'Seeks filmweb.pl database for <b>${movieTitle}</b>.';
pblock.innerHTML = CmdUtils.renderTemplate(previewTemplate, {movieTitle: movieTitle});
function previewResults(htmlResult) {
pblock.innerHTML = parseSearchResult(htmlResult);
};
CmdUtils.previewGet(pblock,
searchURL,
{q: args.object.text, c: 'film'},
previewResults,
"html");
},
execute: function(args) {
var urlParams = {q: args.object.text, c: 'film'};
Utils.openUrlInBrowser(searchURL + Utils.paramsToString(urlParams));
}
});
}
else {
CmdUtils.CreateCommand({
name: 'filmweb',
icon: 'http://gfx.filmweb.pl/gf/favicon.ico',
takes: {'movie title': noun_arb_text},
author: {name: 'Daniel Lorych', email: 'd.lorych@gmail.com'},
license: 'MPL',
description: 'Seeks <a href="' + mainURL + '">Filmweb</a> for movies matching your words.',
preview: function(pblock, inputObject){
var movieTitle = jQuery.trim(inputObject.text);
if(movieTitle.length < 1){
pblock.innerHTML = 'Seeks filmweb.pl database for <i>movie title</i>.';
return;
}
var previewTemplate = 'Seeks filmweb.pl database for <b>${movieTitle}</b>.';
pblock.innerHTML = CmdUtils.renderTemplate(previewTemplate, {movieTitle: movieTitle});
function previewResults(htmlResult) {
pblock.innerHTML = parseSearchResult(htmlResult);
};
CmdUtils.previewGet(pblock,
searchURL,
{q: inputObject.text, c: 'film'},
previewResults,
"html");
},
execute: function(inputObject) {
var urlParams = {q: inputObject.text, c: 'film'};
Utils.openUrlInBrowser(searchURL + Utils.paramsToString(urlParams));
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment