ThunderRhapsody

Google Fixed tab order (not mine, can't find original link)

Jun 15th, 2014
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. //How to use
  2. //Copy all this code (or from where it says "// ==UserScript==" to the end, I don't think it matters that much if you include these top 7 lines)
  3. //click the tampermonkey icon
  4. //click Add a New Script
  5. //Paste in the code
  6. //save
  7. //test
  8.  
  9. // ==UserScript==
  10. // @name Google Fixed Tab Order
  11. // @namespace google.com
  12. // @include https://www.google.co.uk/search?*
  13. // @include https://www.google.co.uk/webhp?*
  14. // @include https://www.google.com/search?*
  15. // @include https://www.google.com/webhp?*
  16. // @version 2.0
  17. // @grant none
  18. // ==/UserScript==
  19.  
  20. (function ()
  21. {
  22. var order = ["Web", "Images", "Videos", "News", "Maps", "Books", "Apps", "Shopping", "Flights"];
  23.  
  24. function observerEnable()
  25. {
  26. observer.observe(document.querySelector("#main"), { childList: true, subtree: true });
  27. }
  28. function observerDisable()
  29. {
  30. observer.disconnect();
  31. }
  32. var observer = new MutationObserver(function(mutations)
  33. {
  34. observerDisable();
  35. fixTabs();
  36. observerEnable();
  37. });
  38. observerEnable();
  39.  
  40. function fixTabs()
  41. {
  42. var parent = document.querySelector("#hdtb_msb");
  43. if (parent == null)
  44. return;
  45.  
  46. var tabs = parent.querySelectorAll(".hdtb_mitem");
  47. if (tabs.length != 9)
  48. return;
  49.  
  50. var more = document.querySelector("#hdtb_more");
  51. var tools = document.querySelector("#hdtb_tls");
  52.  
  53. while (parent.firstChild)
  54. parent.removeChild(parent.firstChild);
  55.  
  56. for (var i = 0; i < order.length; i++)
  57. for (var t = 0; t < tabs.length; t++)
  58. if (order[i] == tabs[t].textContent)
  59. parent.appendChild(tabs[t]);
  60.  
  61. parent.appendChild(tools);
  62. }
  63. fixTabs();
  64. })();
Add Comment
Please, Sign In to add comment