Skip to content

Instantly share code, notes, and snippets.

@karlbohlmark
Created July 10, 2009 11:59
Show Gist options
  • Save karlbohlmark/144447 to your computer and use it in GitHub Desktop.
Save karlbohlmark/144447 to your computer and use it in GitHub Desktop.
//Uppdatering till Parser 2 API av command skriven av Simon Gate, simon@noona.se
CmdUtils.CreateCommand({
names: ["hitta"],
icon: "http://www.hitta.se/favicon.ico",
description: "Sök på hitta.se.",
help: "hitta [NAMN] i [STAD].",
author: {name: "Karl Böhlmark", email: "karl.bohlmark@gmail.com"},
license: "GPL",
arguments: [{role: 'object', nountype: noun_arb_text}],
preview: function preview(pblock, args) {
var split = args.object.html.match(/^(.+)(?:\si\s|,|\såp\s)(.+)/i);
if(split != null) {
pblock.innerHTML = "Sök efter <b>" + split[1] + "</b> som bor i <b>" + split[2] + "</b>.";
} else if (args.object.html.length > 0){
pblock.innerHTML = "Sök efter <b>" + args.object.html + "</b>.";
}
},
execute: function execute(args) {
var split = args.object.html.match(/^(.+)(?:\si\s|,)(.+)/i);
if (split != null) {
var what = split[1];
var where = split[2];
} else
{
var what = args.object.html;
}
if (what != "" && where != "") {
Utils.openUrlInBrowser("http://www.hitta.se/SearchMixed.aspx?vad="+what+"&var="+where);
} else {
Utils.openUrlInBrowser("http://www.hitta.se/SearchMixed.aspx?vad="+what);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment