Advertisement
Soullesswaffle

Google navbar Grooveshark entry

Jul 3rd, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           GoogleGroovesharkBar
  3. // @description    Adds a 'Search on Grooveshark' option to Google's black navigation bar
  4. // @include        google.com/*
  5. // @include        google.nl/*
  6. // @include        https://www.google.com/*
  7. // @include        https://www.google.nl/*
  8. // @include        http://www.google.com/*
  9. // @include        http://www.google.nl/*
  10. // @require        http://code.jquery.com/jquery-1.10.1.min.js
  11.  
  12. //by Soullesswaffle
  13. //Versions : 0.8
  14. // ==/UserScript==
  15.  
  16. function addGroove(retrievedText) {
  17.     var bar = document.getElementById("gbzc");
  18.     var grooveyImage = document.createElement("img");
  19.     var link = document.createElement("a");
  20.     var listy = document.createElement("li");
  21.     grooveyImage.src = "http://cdn.androidpolice.com/wp-content/uploads/2012/08/nexusae0_146.png";
  22.     grooveyImage.style.height = "28px";
  23.  
  24.     //grooveyImage.alt doesn't display in chrome for me, but when inspecting the element the alt attribute is present and correct.
  25.     if (retrievedText === "") {
  26.         link.href = "http://grooveshark.com";
  27.         grooveyImage.alt = "Grooveshark";
  28.     } else {
  29.         link.href = "http://grooveshark.com/#!/search?q=" + retrievedText;
  30.         grooveyImage.alt = "Search for '" + retrievedText + "' on Grooveshark";
  31.     }
  32.  
  33.     //Nest and display everything
  34.     link.appendChild(grooveyImage);
  35.     listy.appendChild(link);
  36.     listy.id = "grvshrkbtn";
  37.     if (!document.getElementById("grvshrkbtn")) {
  38.         bar.appendChild(listy);
  39.     } else {
  40.         bar.replaceChild(listy, document.getElementById("grvshrkbtn"));
  41.     }
  42. }
  43.  
  44. //Initialize
  45. $(document).ready(function () {
  46.     addGroove(document.getElementById("gbqfq").value);
  47. });
  48.  
  49. //Watch textfield for changes
  50. $("#gbqfq").bind("input", function () {
  51.     addGroove($(this).val());
  52. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement