Advertisement
Twilypastes

patch1-homepage-twily

Jun 2nd, 2015
628
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/homepage#Firefox
  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.location=search[i][1]+q.substr(0,x).replace(/&/g,"%26");
  21.                     window.location=search[i][1]+q.substr(2).replace(/&/g,"%26");
  22.                     return true;
  23.                 }
  24.             }
  25.             // Invalid "!i", use default
  26.             //window.location=ss+q.substr(0,x).replace(/&/g,"%26");
  27.             window.location=ss+q.substr(2).replace(/&/g,"%26");
  28.         } else {
  29.             // "!i" where not specified, use default
  30.             window.location=ss+q.replace(/&/g,"%26");
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement