-
-
Save dlorych/120581 to your computer and use it in GitHub Desktop.
filmweb.pl search ubiquity keyword
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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