Classic Google Top Bar fixer

Brings back the old black top bar from 2011 - 2014.

  1. // ==UserScript==
  2. // @name Classic Google Top Bar fixer
  3. // @namespace https://discord.gg/DNeMsgXaz6
  4. // @version 8.0.0
  5. // @description Brings back the old black top bar from 2011 - 2014.
  6. // @author Default
  7. // @match https://www.google.com/
  8. // @match https://www.google.com/?*
  9. // @match https://www.google.com/search*
  10. // @match https://www.google.com/imghp*
  11. // @run-at document-body
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. var topBar
  16.  
  17. function detectURL() {
  18. if (window.location.href.includes('imghp') || window.location.href.includes('tbm=isch')) {
  19. return 1
  20. } else if (window.location.href.includes('tbm=nws')) {
  21. return 5
  22. } else {
  23. return 0
  24. }
  25. }
  26.  
  27. function toggleMore() {
  28. event.preventDefault()
  29. if (!topBar.querySelector('div.tbLeftItems li.tbDropdown a.tbDropdown').classList.contains('tbOpen')) {
  30. topBar.querySelector('div.tbLeftItems li.tbDropdown a.tbDropdown').classList.add('tbOpen')
  31. topBar.querySelector('div.tbLeftItems li.tbDropdown div.tbMoreMenu').classList.add('tbOpen')
  32. } else if (topBar.querySelector('div.tbLeftItems li.tbDropdown a.tbDropdown').classList.contains('tbOpen')) {
  33. topBar.querySelector('div.tbLeftItems li.tbDropdown a.tbDropdown').classList.remove('tbOpen')
  34. topBar.querySelector('div.tbLeftItems li.tbDropdown div.tbMoreMenu').classList.remove('tbOpen')
  35. }
  36. }
  37.  
  38. function toggleAccount() {
  39. event.preventDefault()
  40. if (!topBar.querySelector('div.tbRightItems li.tbDropdown div.tbAccountMenu').classList.contains('tbOpen')) {
  41. topBar.querySelector('div.tbRightItems li.tbDropdown div.tbAccountMenu').classList.add('tbOpen')
  42. } else if (topBar.querySelector('div.tbRightItems li.tbDropdown div.tbAccountMenu').classList.contains('tbOpen')) {
  43. topBar.querySelector('div.tbRightItems li.tbDropdown div.tbAccountMenu').classList.remove('tbOpen')
  44. }
  45. }
  46.  
  47. function getEmail() {
  48. const emailAddress = document.querySelectorAll('div.gb_Cb')[0];
  49. if (emailAddress) {
  50. return emailAddress
  51. } else {
  52. return 'Sign in'
  53. }
  54. }
  55.  
  56. function createtopBar() {
  57. /* Create the full html element */
  58. topBar = document.createElement("div");
  59. topBar.classList.add('topBar')
  60. topBar.innerHTML =
  61. `<div class="tbLeftItems">
  62. <a href="https://www.google.com">Search</a>
  63. <a href="https://www.google.com/imghp">Images</a>
  64. <a href="https://maps.google.com">Maps</a>
  65. <a href="https://play.google.com">Play</a>
  66. <a href="https://www.youtube.com">YouTube</a>
  67. <a href="https://news.google.com">News</a>
  68. <a href="https://mail.google.com">Gmail</a>
  69. <a href="https://drive.google.com">Drive</a>
  70. <li class="tbDropdown">
  71. <a class="tbDropdown" onClick="toggleMore()" href="https://about.google/intl/en/products/">More</a>
  72. <div class="tbMoreMenu">
  73. <a href="https://calendar.google.com">Calendar</a>
  74. <a href="https://translate.google.com">Translate</a>
  75. <a href="https://store.google.com/category/phones">Mobile</a>
  76. <a href="https://books.google.com">Books</a>
  77. <a href="https://pay.google.com">Offers</a>
  78. <a href="https://wallet.google.com">Wallet</a>
  79. <a href="https://shopping.google.com">Shopping</a>
  80. <a href="https://www.blogger.com">Blogger</a>
  81. <a href="https://web.archive.org/web/20130801001727id_/http://www.google.com/reader/about/">Reader</a>
  82. <a href="https://www.google.com/finance/">Finance</a>
  83. <a href="https://photos.google.com">Photos</a>
  84. <a href="http://www.google.com/videohp">Videos</a>
  85. <div class="tbSeperator"></div>
  86. <a href="https://about.google/intl/en/products/">Even more »</a>
  87. </div>
  88. </li>
  89. </div>
  90. <div class="tbRightItems">
  91. <li class="tbDropdown tbRight">
  92. <a class="tbRight" href="https://accounts.google.com/">Sign in</a>
  93. <div class="tbAccountMenu">
  94. <div class="row main">
  95. <img id="tbProfilePic"></img>
  96. <div class="column">
  97. <span id="tbName">Your Name</span>
  98. <span id="tbEmail">example@gmail.com</span>
  99. <div class="row">
  100. <a href="https://myaccount.google.com">Account</a>
  101. <div id="tbSep"></div>
  102. <a href="https://policies.google.com/privacy">Privacy</a>
  103. </div>
  104. </div>
  105. </div>
  106. <a id="tbSwitch" href="https://accounts.google.com/SignOutOptions?hl=en&continue=https://www.google.com">Switch Accounts</a>
  107. </div>
  108. </li>
  109. <div class="tbSeperator"></div>
  110. <a class="tbSettings" href="https://www.google.com/preferences"></>
  111. </div>`
  112. /* Detect URL and make sure the correct item is selected */
  113. topBar.querySelector('div.tbLeftItems').children[detectURL()].classList.add('tbSelected')
  114.  
  115. /* Listen for when the more button is clicked and call the toggle function */
  116. topBar.querySelector('div.tbLeftItems li.tbDropdown a.tbDropdown').addEventListener("click", toggleMore);
  117.  
  118. /* Call the function to detect if the user is signed in and display their email address */
  119. setTimeout(function() {
  120. if (getEmail()) {
  121. const accountButton = topBar.querySelector('div.tbRightItems li.tbDropdown a')
  122. const email = getEmail()
  123. accountButton.textContent = email.nextSibling.textContent
  124. accountButton.classList.add('tbDropdown')
  125.  
  126. topBar.querySelector('div.tbRightItems li.tbDropdown div.tbAccountMenu div.row img#tbProfilePic').src = document.querySelectorAll('img.gb_n.gbii')[0].src.replace('=s32', '=s256')
  127. topBar.querySelector('div.tbRightItems li.tbDropdown div.tbAccountMenu div.row div.column span#tbName').textContent = email.textContent
  128. topBar.querySelector('div.tbRightItems li.tbDropdown div.tbAccountMenu div.row div.column span#tbEmail').textContent = email.nextSibling.textContent
  129.  
  130. /* Listen for when the account button is clicked and call the toggle function */
  131. accountButton.addEventListener("click", toggleAccount);
  132. }
  133. }, 2000);
  134. document.body.insertBefore(topBar, document.body.firstChild);
  135. }
  136.  
  137. createtopBar()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址