Active Topics

 


Reply
Thread Tools
Posts: 46 | Thanked: 36 times | Joined on Sep 2008
#1
This tweak is a nice time saver. It lets you type:

wp bats
g freebird tabs
az "some book"
yt "youtube vid"
itt some ITT thread

in the location bar to search Wikipedia or google, etc., and allows you (with some text editing) to set up custom searches. It consists of downloading a htm file and setting the about:config setting in the browser to use that file for default searches.

1. Download search.htm, included at the end of this post, and save it at a know location, e.g. /home/user/search.htm
2. Type about:config in the browser.
3. Set keyword.enabled to true (if it is not true already)
4. Set keyword.URL to file:///home/user/search.htm?q=
--
5. For custom searches, a minor bit of editing is required. At the very bottom of search.htm, there is a series of lines, of the form
case "g": SearchSite = "http://www.google.com/search?q=%s"; break
Copy this line, change "g" to the new keyword you want, the website to the new search website, substituting %s for the search term. (For example, change g to cnn, search "XXXX" on CNN.com, copy the resulting URL, and replace XXXX with %s)

And that's it! Here is the htm file:

<HTML><HEAD><SCRIPT LANGUAGE="JavaScript">

if( typeof(window.safeGet) != typeof(false) ) { window.safeGet = new Object(); }
function locclean( locvarcl, loctrue ) {
var locvarar = new Array(/\+/g,/%27/g,/%5C/g,/%0A/g,/%0D/g,/%0C/g,/%0B/g), varlocar = new Array(" ","\\'","\\\\","\\n","\\r","\\f","'+unescape('%0B' )+'"), x;
if( loctrue ) { locvarar.length = 1; } //If I'm not using eval(), I only need to convert the +
for( x = 0; x < locvarar.length ; x++ ) {
locvarcl = locvarcl.replace( locvarar[x], varlocar[x] );
}
return unescape( locvarcl );
}
function findString(tempVal) { //returns the length of a valid string plus the whitespace around it
if( tempVal.replace( /^\s*/, "" ).charAt( 0 ) != "'" && tempVal.replace( /^\s*/, "" ).charAt( 0 ) != '"' ) { return -1; }
var backSl = 0; //I did have a regular expression to detect valid strings but NS4 had a bug that made it fail.
for( var y = 1; ( backSl % 2 || tempVal.replace( /^\s*/, "" ).charAt( y ) != tempVal.replace( /^\s*/, "" ).charAt( 0 ) ) && y < tempVal.length - 1; y++ ) {
if( !tempVal.replace( /^\s*/, "" ).charAt( y ).replace( /[\n\r\f]/, "" ) ) { return -1; }
if( tempVal.replace( /^\s*/, "" ).charAt( y ) == "\\" && ( tempVal.replace( /^\s*/, "" ).charAt( y + 1 ) == "\\" || tempVal.replace( /^\s*/, "" ).charAt( y + 1 ) == tempVal.replace( /^\s*/, "" ).charAt( 0 ) ) ) {
backSl++; } else { backSl = 0; } } if( y == 1 ) { y = 0; }
return y + 1 + ( tempVal.length - tempVal.replace( /^\s*/, "" ).length ) + ( tempVal.replace( /^\s*/, "" ).substr( y + 1 ).length - tempVal.replace( /^\s*/, "" ).substr( y + 1 ).replace( /^\s*/, "" ).length );
}
var lvTempVar = window.location.href.replace( /#.*/, "" ).replace(/'/g,'%27').replace( /&/g, "&window."+(safeGet?'safeGet.':'') ) + "&", getVars = new Array(), locvarx = 0, locvartemp = "";
if( lvTempVar.indexOf( "?" ) + 1 && lvTempVar.substr( lvTempVar.indexOf( "?" ) + 1 ).length > 1 ) {
//there are variables, what are they?
lvTempVar = ( "window." + (safeGet?'safeGet.':'') + lvTempVar.substr( lvTempVar.indexOf( "?" ) + 1 ) );
while( lvTempVar.indexOf( "&" ) + 1 ) {
locvartemp += locclean( lvTempVar.substr( 0, lvTempVar.indexOf( "=" ) ), true ) + lvTempVar.substring( lvTempVar.indexOf( "=" ), lvTempVar.indexOf( "&" ) + 1 );
lvTempVar = lvTempVar.substr( lvTempVar.indexOf( "&" ) + 1 );
} //that unescaped the variable names but not the contents
lvTempVar = "window";
while( locvartemp.length > 0 ) {
if( "^fdg".replace( /\W[\w\W]*/, "" ) ) { window.defaultStatus = "Browser bug detected. Script aborted without error."; break; }
if( locvartemp.charAt( locvartemp.search( /\W/ ) ) == "." ) { //That last one was an object
if( typeof( eval( lvTempVar ) ) != "object" ) { eval( lvTempVar + " = new Object();" ); } //this is a valid object. create it.
locvartemp = locvartemp.substr( locvartemp.indexOf( "." ) + 1 );
//add the next valid word to the text to be evaluated
lvTempVar += "." + locvartemp.substr( 0, locvartemp.search( /\W/ ) );
if( locvartemp.search( /[a-z_]/i ) != 0 ) { locvartemp = "&"; continue; } //the . after an object MUST be followed by a-z, A-Z, _. Force safe failure
} else { if( locvartemp.charAt( locvartemp.search( /\W/ ) ) == "[" ) { //That last one was an array
if( typeof( eval( lvTempVar ) ) != "object" ) { eval( lvTempVar + " = new Array();" ); }
if( locvartemp.charAt( locvartemp.indexOf( "[" ) + findString( locvartemp.substr( locvartemp.indexOf( "[" ) + 1 ) ) + 1 ) == "]" ) { //they have used quotes.
lvTempVar += locvartemp.substr( locvartemp.indexOf( "[" ), findString( locvartemp.substr( locvartemp.indexOf( "[" ) + 1 ) ) + 2 ); //valid. Add [THEIR_STRING] to the text to be evaluated
locvartemp = locvartemp.substr( locvartemp.indexOf( "[" ) + findString( locvartemp.substr( locvartemp.indexOf( "[" ) + 1 ) ) + 2 );
} else { //they should have used a number. Have they? If not, force safe failure
if( "" + parseInt( locvartemp.substring( locvartemp.indexOf( "[" ) + 1, locvartemp.indexOf( "]" ) ) ) + "" != locvartemp.substring( locvartemp.indexOf( "[" ) + 1, locvartemp.indexOf( "]" ) ).replace( /\s/g, "" ) || isNaN( parseInt( locvartemp.substring( locvartemp.indexOf( "[" ) + 1, locvartemp.indexOf( "]" ) ) ) ) ) {
locvartemp = "&"; continue; }
lvTempVar += locvartemp.substring( locvartemp.indexOf( "[" ), locvartemp.indexOf( "]" ) + 1 ); //valid. Add [THEIR_NUM] to the text to be evaluated
locvartemp = locvartemp.substr( locvartemp.indexOf( "]" ) + 1 );
}
if( locvartemp.charAt( 0 ) != "[" && locvartemp.charAt( 0 ) != "." && locvartemp.charAt( 0 ) != "=" ) { locvartemp = "&"; continue; } //the ] after an array MUST be followed by . or [ or =. Force safe failure
} else { if( locvartemp.charAt( locvartemp.search( /\W/ ) ) == "=" ) { //This is the end of the variable name
//this is a valid variable. create it/them.
eval( lvTempVar + " = '" + locclean( locvartemp.substring( locvartemp.indexOf( "=" ) + 1, locvartemp.indexOf( "&" ) ) ) + "';" );
if( window.useArray ) { //they want the getVars array. Fill it up
getVars[lvTempVar.replace( (safeGet?/window\.safeGet\./:/window\./), "" )] = locclean( locvartemp.substring( locvartemp.indexOf( "=" ) + 1, locvartemp.indexOf( "&" ) ), true );
getVars[locvarx] = locclean( locvartemp.substring( locvartemp.indexOf( "=" ) + 1, locvartemp.indexOf( "&" ) ), true );
locvarx++;
}
//prepare to use the next variable
locvartemp = locvartemp.substr( locvartemp.indexOf( "&" ) + 1 );
lvTempVar = locvartemp.substr( 0, locvartemp.search( /\W/ ) );
} else { //safe failure
window.defaultStatus = "Invalid variable format. Script aborted without error.";
getVars = new Array(); //remove older answers
break; //They have put in a variable that does not have a valid name format. abort.
}
}
}
}
}
locvartemp = null; lvTempVar = null; locvarx = null; //clear up

i = safeGet.q.indexOf(" ")
engine = safeGet.q.substr(0,i)
term = safeGet.q.substr(i+1)
switch (engine) {
case "g": SearchSite = "http://www.google.com/search?q=%s"; break
case "gg": SearchSite = "http://www.google.com/search?q=%s&btnI=I'm+Feeling+Lucky"; break
case "wp": SearchSite = "http://en.wikipedia.org/wiki/search?search=%s&go=Go"; break
case "az": SearchSite = "http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Daps&field-keywords=%s&x=0&y=0"; break
case "yt": SearchSite= "http://www.youtube.com/results?search_query=%s&search_type="; break
case "tl": SearchSite= "http://www.teamliquid.net/tlpd/search.php?search=%s&type=all&x=18&y=7"; break
case "d": SearchSite = "http://dictionary.reference.com/browse/%s";break
case "itt": SearchSite = "http://www.internettablettalk.com/search/results.html?cx=partner-pub-1540416982644573%3As1i8nedfnqe&cof=FORID%3A9&q=%s& sa=Go"; break
case "ma": SearchSite = "http://search.maemo.org/search?q=%s&btnG=Search&site=maemo-org&client=maemo-org&proxystylesheet=maemo-org&output=xml_no_dtd"; break
default: SearchSite= ""
}
window.location = SearchSite.replace("%s",term)
</SCRIPT></HEAD>
</HTML>

Last edited by q335r49; 2009-01-31 at 04:24.
 

The Following 8 Users Say Thank You to q335r49 For This Useful Post:
Reply

Tags
browser, keyword search


 
Forum Jump


All times are GMT. The time now is 03:54.