Advertisement
Guest User

grease monkey script to fix google search tabs order

a guest
Aug 12th, 2014
1,795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Google Fixed Tab Order
  3. // @namespace   google.com
  4. // @include     https://www.google.com/search?*
  5. // @include     https://www.google.com/webhp?*
  6. // @include     https://www.google.ca/search?*
  7. // @include     https://www.google.ca/webhp?*
  8. // @version     2.0
  9. // @grant       none
  10. // ==/UserScript==
  11.  
  12. (function ()
  13. {
  14.     var order = ["Web", "Images", "Videos", "News", "Maps", "Books", "Apps", "Shopping", "Flights"];
  15.  
  16.     function observerEnable()
  17.     {
  18.         observer.observe(document.querySelector("#main"), { childList: true, subtree: true });
  19.     }
  20.     function observerDisable()
  21.     {
  22.         observer.disconnect();
  23.     }
  24.     var observer = new MutationObserver(function(mutations)
  25.     {
  26.         observerDisable();
  27.         fixTabs();
  28.         observerEnable();
  29.     });
  30.     observerEnable();
  31.    
  32.     function fixTabs()
  33.     {
  34.         var parent = document.querySelector("#hdtb_msb");
  35.         if (parent == null)
  36.             return;
  37.  
  38.         var tabs = parent.querySelectorAll(".hdtb_mitem");
  39.  
  40.         var more = document.querySelector("#hdtb_more");
  41.         var tools = document.querySelector("#hdtb_tls");
  42.  
  43.         while (parent.firstChild)
  44.             parent.removeChild(parent.firstChild);
  45.  
  46.         for (var i = 0; i < order.length; i++)
  47.             for (var t = 0; t < tabs.length; t++)
  48.                 if (order[i] == tabs[t].textContent)
  49.                     parent.appendChild(tabs[t]);
  50.                    
  51.         parent.appendChild(tools);
  52.     }
  53.     fixTabs();
  54. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement