Advertisement
Twilypastes

patch1-homepage-sidebar-twily

Sep 20th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.         Author:       Twily                                                                 2015
  3.         Description:  Optional patch for using "!i" before (in front of) the search query string
  4.         Original:     http://twily.info/firefox/homepage-sidebar.html
  5.         Instructions: Replace the original 'handleQuery' function with the code below
  6. */
  7.  
  8. function handleQuery(e,q) { // Handle search query
  9.     var key=e.keyCode || e.which;
  10.  
  11.     if(key==13) { // Enter
  12.         //var x=q.lastIndexOf("!");
  13.         var x=q.indexOf("!");
  14.  
  15.         //if(x!=-1 && x>=q.length-2) {
  16.         if(x==0) {
  17.             for(var i=0;i<search.length;i++) {
  18.                 //if(search[i][0]==q.substr(x)) { // Find "*!i"
  19.                 if(search[i][0]==q.substr(0,2)) { // Find "!i*"
  20.                     //window.open(search[i][1]+q.substr(0,x).replace(/&/g,"%26"));
  21.                     window.open(search[i][1]+q.substr(2).replace(/&/g,"%26"));
  22.  
  23.                     $('q').value="";
  24.                     $('q').focus();
  25.                     return true;
  26.                 }
  27.             }
  28.             // Invalid "!i", use default
  29.             //window.open(ss+q.substr(0,x).replace(/&/g,"%26"));
  30.             window.open(ss+q.substr(2).replace(/&/g,"%26"));
  31.         } else {
  32.             // "!i" where not specified, use default
  33.             window.open(ss+q.replace(/&/g,"%26"));
  34.         }
  35.  
  36.         $('q').value="";
  37.         $('q').focus();
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement