Guest User

Untitled

a guest
Sep 16th, 2015
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String.prototype.replaceChars = function(character, replacement){
  2.     var str = this;
  3.     var a;
  4.     var b;
  5.     for(var i=0; i < str.length; i++){
  6.         if(str.charAt(i) == character){
  7.             a = str.substr(0, i) + replacement;
  8.             b = str.substr(i + 1);
  9.             str = a + b;
  10.         }
  11.     }
  12.     return str;
  13. }
  14.  
  15. function search(query){
  16.     switch(query.substr(0, 2)){
  17.         case "-d":
  18.             query = query.substr(3);
  19.             window.location = "https://duckduckgo.com/?q=" +
  20.                 query.replaceChars(" ", "+");
  21.             break;
  22.         case "-y":
  23.             query = query.substr(3);
  24.             window.location =
  25.                 "https://www.youtube.com/results?search_query=" +
  26.                 query.replaceChars(" ", "+");
  27.             break;
  28.         case "-w":
  29.             query = query.substr(3);
  30.             window.location =
  31.                 "https://en.wikipedia.org/w/index.php?search=" +
  32.                 query.replaceChars(" ", "%20");
  33.             break;
  34.         case "-4":
  35.             query = query.substr(3);
  36.             window.location =
  37.                 "http://boards.4chan.org/" +
  38.                 query.replaceChars(" ", "%20");
  39.             break;
  40.         case "-r":
  41.             query = query.substr(3);
  42.             window.location =
  43.                 "http://www.reddit.com/r/" +
  44.                 query.replaceChars(" ", "%20");
  45.             break;
  46.         case "-i":
  47.             query = query.substr(3);
  48.             window.location =
  49.                 "https://www.google.co.uk/search?q=" +
  50.                 query.replaceChars(" ", "%20") + "&tbm=isch";
  51.             break;
  52.         default:
  53.             window.location="https://www.google.co.uk/#q=" +
  54.                 query.replaceChars(" ", "+");
  55.     }
  56. }
  57.  
  58. window.onload = function(){
  59.     // search
  60.     searchinput = document.getElementById("searchinput");
  61.     if(!!searchinput){
  62.         searchinput.addEventListener("keypress", function(a){
  63.             var key = a.keyCode;
  64.             if(key == 13){
  65.                 var query = this.value;
  66.                 search(query);
  67.             }
  68.         });
  69.     }
  70.  
  71.     // jump to search when tab is pressed
  72.     var search_sqr = document.getElementById("search_sqr");
  73.  
  74.         }
Add Comment
Please, Sign In to add comment