Skip to content

Instantly share code, notes, and snippets.

@xnyhps
Created April 15, 2009 20:10
Show Gist options
  • Save xnyhps/95996 to your computer and use it in GitHub Desktop.
Save xnyhps/95996 to your computer and use it in GitHub Desktop.
lmakeSearchCommand({
name: "Wowhead",
url: "http://www.wowhead.com/?search={QUERY}",
icon: "http://www.wowhead.com/favicon.ico",
description: "Searches Wowhead for your keywords.",
author: {name: "Thijs Alkemade"},
license: "GPL",
preview: function(pblock, directObject) {
var searchTerm = directObject.text;
var pTemplate = "Searches Wowhead for <b>${query}</b>";
var pData = {query: searchTerm};
pblock.innerHTML = CmdUtils.renderTemplate(pTemplate, pData);
var url = "http://www.wowhead.com/?search=" + searchTerm + "&opensearch";
jQuery.get( url, {}, function(data) {
var names = data[1];
var properties = data[7];
var results = new Array();
var types = new Array();
types[1] = "npc";
types[2] = "object";
types[3] = "item";
types[4] = "itemset";
types[5] = "quest";
types[6] = "spell";
types[7] = "zone";
types[8] = "faction";
for(var i = 0; i < names.length; ++i) {
results[i] = {
property: properties[i],
name: names[i],
type: types[properties[i][0]],
image: (properties[i][0] == 3 ? "http://static.wowhead.com/images/icons/small/" + properties[i][2].toLowerCase() + ".jpg" : "")
};
}
pblock.innerHTML = CmdUtils.renderTemplate( "<style>@import 'http://www.wowhead.com/widgets/power/power.css?3'; .noitem {color: rgb(255, 209, 0);} .wowhead {font-family: Verdana}</style>{for result in results}<div class=\"wowhead\"><div style=\"background-image: url('${result.image}'); float: left; width: 18px; margin-right: 2px; height: 18px\"></div<a class=\"{if result.property[0] == 3}q${result.property[3]}{else}noitem{/if}\" href=\"http://www.wowhead.com/?${result.type}=${result.property[1]}\">${result.name}</a></div>{/for}",{results:results});
}, "json");
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment