var goosh = new Object();
goosh.lib = new Object();
// thanks to Michael Schwarz for this function
goosh.lib.namespace = function (ns)
{
var parts = ns.split(".");
var root = window;
for(var i=0; i
");
goosh.gui.showinput();
goosh.gui.focusinput();
goosh.gui.scroll();
}
goosh.gui.outln = function(text){
goosh.gui.out(text+"
");
}
goosh.gui.out = function(text){
//goosh.gui.outputel.innerHTML += text;
var div = document.createElement("div");
div.innerHTML = text;
goosh.gui.outputel.appendChild(div);
return div;
}
goosh.gui.less = function(text){
return ""+text+"";
}
goosh.gui.info = function(text){
return ""+text+"";
}
goosh.gui.clear = function(){
goosh.gui.outputel.innerHTML = "";
}
goosh.gui.showinput = function(){
goosh.gui.inputel.style['display'] = 'block';
}
goosh.gui.hideinput = function(){
goosh.gui.inputel.style['display'] = 'none';
}
goosh.gui.focusinput = function(){
var txt = "";
//if (document.getSelection) txt = document.getSelection();
if (document.selection) txt = document.selection.createRange().text;
else if (window.getSelection) txt = window.getSelection().toString();
if(txt.length == 0){
document.f.q.value = document.f.q.value; // for safari
if(goosh.gui.inputel.style['display'] != 'none') document.f.q.focus();
}
}
goosh.gui.updateprompt = function(){
goosh.gui.prompt = goosh.config.user+"@"+goosh.config.host+":/"+goosh.config.mode+goosh.config.pend;
goosh.gui.promptel.innerHTML = goosh.gui.prompt;
}
goosh.gui.scroll = function(){
window.scrollBy(0, 122500);
}
goosh.gui.setstyle = function(ele,prop,val){
try{
var el = goosh.gui.el(ele);
el.style[prop] = val;
return true;
}
catch(e){
return false;
}
}
goosh.gui.setstyleclass = function(classname,style){
//goosh.gui.outputel.innerHTML += text;
var div = document.createElement("div");
var out = "
";
div.innerHTML = out;
goosh.gui.bodyel.appendChild(div);
}
goosh.lib.namespace("goosh.set");
goosh.set.base = function(name,def,txt,min,max){
this.name = name;
this.txt = txt;
this.def = def;
(max) ? this.max = max : this.max = 2000;
(min) ? this.min = min : this.min = 0;
if(min && max) this.txt += " ("+min+".."+max+")";
this.get = function() { return eval (""+this.name+";"); };
this.set = function(val) { eval (""+this.name+" = '"+val+"';"); return true; };
}
goosh.set.list = new Object();
goosh.set.list['lang'] = new goosh.set.base("goosh.config.lang","en","google default language");
goosh.set.list['lang'].set = function(val) {
if (goosh.lang.reverse[val]) goosh.config.lang = val;
else if (goosh.lang.list[val]) goosh.config.lang = goosh.lang.list[val];
else return false;
return true;
};
goosh.set.list['results'] = new goosh.set.base("goosh.config.numres","4","number of results for google-searches",1,100);
goosh.set.list['timeout'] = new goosh.set.base("goosh.config.timeout","4","timeout for ajax requests in seconds",1,100);
goosh.set.list['style.bg'] = new goosh.set.base("goosh.config.bgcolor","#FFFFFF","goosh background color");
goosh.set.list['style.bg'].set = function(val){
if( goosh.gui.setstyle("body","backgroundColor",val) &&
goosh.gui.setstyle("inputfield","backgroundColor",val)){
goosh.config.bgcolor = val;
return true;
}
else return false;
}
goosh.set.list['style.fg'] = new goosh.set.base("goosh.config.fgcolor","#000000","goosh font color");
goosh.set.list['style.fg'].set = function(val){
if( goosh.gui.setstyle("body","color",val) &&
goosh.gui.setstyle("inputfield","color",val)){
goosh.config.fgcolor = val;
return true;
}
else return false;
}
goosh.set.list['style.hl'] = new goosh.set.base("goosh.config.hlcolor","#009900","goosh highlight color");
goosh.set.list['style.hl'].set = function(val){
goosh.gui.setstyleclass(".info","color: "+val);
goosh.gui.setstyleclass("a:visited.info","color: "+val);
goosh.config.hlcolor = val;
return true;
}
goosh.set.list['style.sh'] = new goosh.set.base("goosh.config.shcolor","#666666","goosh 'shaded' color");
goosh.set.list['style.sh'].set = function(val){
goosh.gui.setstyleclass(".less","color: "+val);
goosh.config.shcolor = val;
return true;
}
goosh.set.list['style.link'] = new goosh.set.base("goosh.config.linkcolor","#0000CC","goosh link color");
goosh.set.list['style.link'].set = function(val){
goosh.gui.setstyleclass("a","color: "+val);
goosh.config.linkcolor = val;
return true;
}
goosh.set.list['style.vlink'] = new goosh.set.base("goosh.config.vlinkcolor","#551a8b","goosh visited link color");
goosh.set.list['style.vlink'].set = function(val){
goosh.gui.setstyleclass("a:visited","color: "+val);
goosh.config.vlinkcolor = val;
return true;
}
// #551a8b
//goosh.gui.setstyleclass
goosh.set.list['place.width'] = new goosh.set.base("goosh.config.mapwidth","300","width of map image",20,600);
goosh.set.list['place.height'] = new goosh.set.base("goosh.config.mapheight","150","height of map image",20,500);
goosh.set.list['amazon.reflink'] = new goosh.set.base("goosh.config.reflink","on","Add referer links to amazon product links");
goosh.set.init = function(context,result){
if(goosh.config.user != "guest") {
if(!context) {
goosh.ajax.query("http://goosh.appspot.com/cookie?callback=goosh.set.init");
return;
}
else if(goosh.ajax.iscontext(context)){
goosh.gui.outln("Loading remote settings...");
//alert(result);
goosh.lib.cookie.getfromstr(document.cookie);
goosh.lib.cookie.getfromstr(result,true);
}
}
else {
goosh.gui.outln("Loading local settings...");
goosh.lib.cookie.getfromstr(document.cookie);
}
var cookies = goosh.lib.cookie.getall();
for(key in goosh.set.list){
var c = false;
if(cookies[key]) c = cookies[key];
if(c && goosh.set.list[key].set(c)) {
goosh.gui.outln(" "+key+" => ""+c+"".");
}
else{
goosh.set.list[key].set(goosh.set.list[key].def);
// goosh.gui.outln(key+" = ""+goosh.set.list[key].get()+"".");
}
}
goosh.gui.outln("");
// goosh.gui.updateprompt();
// goosh.gui.showinput();
// goosh.gui.focusinput();
goosh.getquery();
}
goosh.lib.namespace("goosh.ajax");
goosh.ajax.contexts = new Array();
goosh.ajax.lastcontext = false;
goosh.ajax.stopall = function(){
for(key in goosh.ajax.contexts){
goosh.ajax.iscontext(key);
}
}
goosh.ajax.deletecontext = function(context){
goosh.gui.outln('Error: Operation timed out. '+context);
if(!document.all) goosh.gui.outln(goosh.gui.less('If you use the noscript firefox-extension, add "ajax.googleapis.com" to the whitelist.'));
goosh.gui.outln('');
goosh.ajax.contexts[context]=false;
var d = document.getElementById(context);
if(d) document.body.removeChild(d);
goosh.gui.showinput();
goosh.gui.focusinput();
goosh.gui.scroll();
if(!document.all) stop();
}
goosh.ajax.iscontext = function(name){
if(goosh.ajax.contexts[name]){
clearTimeout(goosh.ajax.contexts[name]);
goosh.ajax.contexts[name] =false;
var d = document.getElementById(name);
if(d) document.body.removeChild(d);
return true;
}
else return false;
}
goosh.ajax.getcontext = function(name){
var d = new Date();
var context = d.getTime();
if(name) context = name;
goosh.ajax.contexts[context] = setTimeout("goosh.ajax.deletecontext('"+context+"');",1000*goosh.config.timeout);
return context;
}
goosh.ajax.query = function(url,nohide){
var context = "none";
if(!nohide){
context = goosh.ajax.getcontext();
goosh.ajax.lastcontext = context; // more elegant with return, but doesnt work in opera
goosh.gui.hideinput();
}
var script = document.createElement("script");
document.body.appendChild(script);
script.src = url+'&context='+context+'&';
script.id = context;
}
goosh.lib.namespace("goosh.config");
goosh.config.apikey = "ABQIAAAA0cXSEVCNSwf_x74KTtPJMRShYK5vgJfK0afUKMRqjECszDItkhTOIyZ74499O_ys5nJIQuP4sq4nZg";
goosh.config.user = "guest";
goosh.config.host = "goosh.org";
goosh.config.mode = "web";
goosh.config.pend = "> ";
goosh.config.numres = 4;
goosh.config.timeout = 4;
goosh.config.start=0;
goosh.config.moreobj;
goosh.config.lang = "en";
goosh.config.urls = new Array();
goosh.config.cmdlines = new Array();
goosh.config.cmdqueue = new Array();
goosh.config.reflink = "on";
goosh.lib.namespace("goosh.keyboard");
goosh.keyboard.suggestions = new Array();
goosh.keyboard.suggpos = 1;
goosh.keyboard.suggword ="";
goosh.keyboard.hist = new Array();
goosh.keyboard.histpos = 0;
goosh.keyboard.histtemp = 0;
goosh.keyboard.suggest = function(word){
if(goosh.keyboard.suggpos > goosh.keyboard.suggestions[word].length) goosh.keyboard.suggpos =1;
if(goosh.keyboard.suggestions[word][goosh.keyboard.suggpos])
goosh.gui.inputfield.value = goosh.keyboard.suggestions[word][goosh.keyboard.suggpos];
var d= goosh.gui.inputfield;
if(d.createTextRange){
var t=d.createTextRange();
t.moveStart("character",word.length);
t.select()
} else if (d.setSelectionRange){
d.setSelectionRange(word.length,d.value.length)
}
}
// evil hack for suggest
goosh.keyboard.dummyac = function() {
this.Suggest_apply = function(el,text,sug,temp){
goosh.keyboard.suggestions[text] = sug;
goosh.keyboard.suggest(text);
return true;
}
};
window.googlesug = new Array();
window.googlesug.ac = new goosh.keyboard.dummyac();
goosh.keyboard.keyDownHandler = function(event){
if(!event&&window.event) {
event=window.event;
}
if(event) {
_lastKeyCode=event.keyCode;
}
// We are backspacing here...
if(event&&event.keyCode==9){
event.cancelBubble=true;
event.returnValue=false;
// tab = 9, backsp = 8, ctrl =17, r = 82
//output.innerHTML += event.keyCode+"
";
var word = goosh.keyboard.suggword;
if(word !=""){
if(!goosh.keyboard.suggestions[word]){
goosh.keyboard.suggpos = 1;
// output.innerHTML += "query
";
var script = document.createElement('script');
document.body.appendChild(script);
script.src = "http://www.google.com/complete/search?hl="+goosh.config.lang+"&js=true&qu="+encodeURIComponent(word);
}
else{
goosh.keyboard.suggpos +=2;
goosh.keyboard.suggest(word);
}
}
return false
}
}
goosh.keyboard.mcursor = function(e){
var keycode=e.keyCode;
if(goosh.keyboard.hist.length>0){
if(keycode==38 || keycode==40){
if(goosh.keyboard.hist[goosh.keyboard.histpos]) {
goosh.keyboard.hist[goosh.keyboard.histpos] = goosh.gui.inputfield.value;
}
else
goosh.keyboard.histtemp = goosh.gui.inputfield.value;
}
if(keycode==38){ // up
goosh.keyboard.histpos--;
if(goosh.keyboard.histpos<0) goosh.keyboard.histpos =0;
}
else if(keycode==40){ //down
goosh.keyboard.histpos++;
if(goosh.keyboard.histpos > goosh.keyboard.hist.length)
goosh.keyboard.histpos = goosh.keyboard.hist.length;
}
if(keycode==38 || keycode==40){
if(goosh.keyboard.hist[goosh.keyboard.histpos])
goosh.gui.inputfield.value = goosh.keyboard.hist[goosh.keyboard.histpos];
else
goosh.gui.inputfield.value = goosh.keyboard.histtemp;
}
}
if(keycode!=9 && keycode !=13)
goosh.keyboard.suggword = goosh.gui.inputfield.value;
if(keycode==13){
goosh.command();
}
}
goosh.lib.namespace("goosh.modules");
goosh.lib.namespace("goosh.module");
goosh.lib.namespace("goosh.modobj");
//function yield(){
// if(cmdqueue.length >0) command(cmdqueue.pop());
//}
goosh.modules.list = new Array();
goosh.module.base = function(){
this.mode = false;
// this.more = false;
this.parameters = "";
this.help = "no helptext yet.";
this.helptext = "";
this.hasmore = false;
this.results = new Array();
}
goosh.modules.register = function(name,base){
if(!base) base = "base";
eval(//"search_"+name+".prototype = new search_"+base+"();"+
//"searchers_"+name+" = new search_"+name+"();"+
'goosh.module.'+name+'.prototype = new goosh.module.'+base+';'+
'goosh.modobj.'+name+' = new goosh.module.'+name+';'+
'goosh.modules.list["'+name+'"] = goosh.modobj.'+name+";");
}
// goosh web search module
goosh.module.web = function(){
this.name = "web";
this.aliases = new Array("web","search","s","w");
this.mode = true;
this.start = 0;
this.args ="";
this.help = "google web search";
this.parameters = "[keywords]";
this.helptext = "examples:
"+
"web foo bar - searches the web for "foo bar"
";
// perform the ajax query
this.query = function(cmdstr,query) {
// goosh.ajax.query("//ajax.googleapis.com/ajax/services/search/"+cmdstr+"?v=1.0&start="+this.qstart+"&hl="+goosh.config.lang+"&callback=goosh.modobj."+this.name+".render&q="+encodeURIComponent(query)+'&key='+goosh.config.apikey+"&rsz=large");
var customSearchOptions = {};
customSearchOptions[google.search.Search.RESTRICT_EXTENDED_ARGS] = {
'lr': 'lang_'+goosh.config.lang
// 'gl': 'date'
};
cs = new google.search.CustomSearchControl('004431332481073456201:1y01bmxbens', customSearchOptions);
// cs.enableAds('pub-6992080843066528');
cs.setResultSetSize(goosh.config.results);
google.search.Csedr.addOverride("mysite_");
cs.setSearchStartingCallback(this, function(control, searcher, query)
{
// searcher.setQueryAddition('inurl:' + url);
searcher.setNoHtmlGeneration();
goosh.gui.hideinput();
searching = true;
});
cs.setSearchCompleteCallback(this, function(control, searcher, query)
{
searching = false;
this.hasmore = true;
goosh.gui.showinput();
goosh.gui.focusinput();
goosh.gui.scroll();
});
var drawOptions = new google.search.DrawOptions();
drawOptions.enableSearchResultsOnly();
var div = goosh.gui.out();
cs.draw(div,drawOptions);
window.i = ((goosh.config.numres-1) * this.start);
cs.execute(query,this.start+1);
}
// render html output
this.renderResult = function(context, results, status, details, unused){
var out = "";
var rnum = this.start;
out += "
"+rnum+") | "; out += "";
out += ''+r.title+"";
out += " "; out += r.content; out += " "; out += ''+r.unescapedUrl+""; out += " "; //if(r.thumb) out += ''+r.thumb+" "; out += " |
"+module.name + " | "; if(i==5){ i=0; out += ' |
name | value | default | help | "+ key + " | "; out += ""+goosh.set.list[key].get()+" | " out += ""+goosh.set.list[key].def+" | " out += ""+goosh.set.list[key].txt+" | " out += '
command | aliases | parameters | function |
"; out += ""+module.name + " | ";
if(module.aliases.length >1){
out += "(";
for(i=0;i";
if( module.parameters) out += module.parameters;
out += " | ";
out += ""+ module.help +"\n";
out += " | |