// YOU CAN DO ANYTHING YOU WANT WITH THIS SOURCE AS LONG AS: // - YOU GIVE ME CREDIT SOMEWHERE IN YOUR SOURCE // THANKS // simply tell the user that if no argument is passed, // they will be taken to the site. if an argument is passed, // then the site will be searched with their query function thePreview(pblock, query, siteName) { if (!query.text || query.text == "go") pblock.innerHTML = "Go to " + siteName; else pblock.innerHTML = "Search " + siteName + " for " + query.text; } // this actually determines the action and then invokes it function SearchOrGoTo(queryUrl, query) { var search_string = encodeURIComponent(query.text); if (!search_string || search_string == "go") Utils.openUrlInBrowser(queryUrl.substring(0, queryUrl.indexOf('/', 8) + 1)); else Utils.openUrlInBrowser(queryUrl.replace("{QUERY}", search_string)); } // this is a function which automates the creation of the commands, // to avoid duplicate code :D function generateSearchCommand(siteName, cmdName, queryUrl) { CmdUtils.CreateCommand({ name: cmdName, takes: {query: noun_arb_text}, description: "Searches or goes to " + siteName, author: {name: "Blaenk", homepage: "http://www.blaenkdenum.com"}, icon: queryUrl.substring(0, queryUrl.indexOf('/', 8) + 1) + "/favicon.ico", preview: function(pblock, query) { thePreview(pblock, query, siteName); }, execute: function(query) { SearchOrGoTo(queryUrl, query); } }); } var sites = [ { name : "Google", command : "g", queryUrl : "http://www.google.com/search?q={QUERY}" }, { name : "Wikipedia", command : "w", queryUrl : "http://en.wikipedia.org/wiki/Special:Search?search={QUERY}" }, { name : "IMDB", command : "i", queryUrl : "http://www.imdb.com/find?q={QUERY}" }]; for (i = 0; i < sites.length; i++) { generateSearchCommand(sites[i].name, sites[i].command, sites[i].queryUrl); }