SuMo Top Menu Hover Remover

On the Mozilla Support site, change the top menus to show on click rather than mouseover, subdue the background colors

  1. // ==UserScript==
  2. // @name SuMo Top Menu Hover Remover
  3. // @description On the Mozilla Support site, change the top menus to show on click rather than mouseover, subdue the background colors
  4. // @author Jefferson "jscher2000" Scher
  5. // @namespace JeffersonScher
  6. // @copyright Copyright 2016 Jefferson Scher (5/5/2016)
  7. // @license BSD 3-clause
  8. // @include https://support.mozilla.org/*
  9. // @version 0.5
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. // Modify CSS hover menus to open and close with a click
  14. var menupads = document.querySelectorAll('#aux-nav > ul > li');
  15. for (var i=0; i<menupads.length; i++){
  16. var droplist = menupads[i].querySelector('ul');
  17. if (droplist) { // remove href and attach toggle function
  18. var link = menupads[i].querySelector("a");
  19. link.href = "javascript:void(0);";
  20. link.addEventListener("click", updateMenus, false);
  21. link.title = "Open menu";
  22. }
  23. }
  24.  
  25. // Style changes
  26. /* Override this hover rule that shows the drop menu
  27. #aux-nav > ul > li:hover > ul {
  28. display: block;
  29. }
  30. */
  31. var r = "#aux-nav > ul > li:hover > ul {display:none;} ";
  32.  
  33. /* Make the background colors less jarring
  34. #aux-nav > ul > li:hover {
  35. background: #fff;
  36. }
  37. #aux-nav > ul > li > a:hover {
  38. background-color: #fff;
  39.  
  40. #aux-nav > ul > li > ul {
  41. background: #fff;
  42. }
  43. */
  44. r += "#aux-nav > ul > li:hover, #aux-nav > ul > li > a.menuopen, #aux-nav > ul > li > ul {background-color:#d2e9fc !important;} #aux-nav > ul > li > a:hover {background-color:transparent !important;}";
  45.  
  46. var s = document.createElement("style");
  47. s.type = "text/css";
  48. s.appendChild(document.createTextNode(r));
  49. document.body.appendChild(s);
  50.  
  51. function updateMenus(evt){
  52. // Event is on a link element
  53. var ael = evt.target;
  54. var opened = toggleSiblingList(ael);
  55. if (opened){ // close other open lists, if any
  56. var nowopen = document.getElementsByClassName('menuopen');
  57. if (nowopen.length > 1) {
  58. for (var i=0; i<nowopen.length; i++) {
  59. if (nowopen[i] != ael) toggleSiblingList(nowopen[i]);
  60. }
  61. }
  62. }
  63. return false;
  64. }
  65.  
  66. function toggleSiblingList(ael){
  67. var siblist = ael.nextElementSibling;
  68. if (siblist){
  69. if (siblist.style.display != "block"){
  70. siblist.style.display = "block";
  71. if (ael.className) ael.className += " menuopen";
  72. else ael.className = " menuopen";
  73. ael.title = "Close menu";
  74. return true;
  75. } else {
  76. siblist.style.display = "none";
  77. if (ael.className) ael.className = ael.className.replace(" menuopen", "");
  78. ael.title = "Open menu";
  79. return false;
  80. }
  81. } else {
  82. return false;
  83. }
  84. }

QingJ © 2025

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