Sergey Astanin avatar Sergey Astanin committed c2e2cf5

toggle button to expand/collapse google bar

Comments (0)

Files changed (1)

Minimize_Navigation_Bars_in_Gmail.user.js

 // ==UserScript==
 // @name        Minimize Navigation Bars in Gmail
 // @namespace   https://github.com/astanin
-// @include     https://mail.google.com/*
+// @include     https://mail.google.tld/*
 // @version     1.0
 // @grant       none
 // ==/UserScript==
 
-// TODO: make it expandable
-function hideBars() {
-   document.getElementById("gb").style.display = "none";
+function addToggleButton() {
+    var tb = document.getElementById("toggle_google_bars");
+    var gb = document.getElementById("gb");
+
+    if (tb) {
+        return;
+    }
+    if (!gb) { // try to add toggle button later (several times)
+        window.triedToAddToggleButton += 1;
+        if (window.triedToAddToggleButton < 5) {
+            setTimeout(addToggleButton, 2000);
+        }
+        return;
+    }
+
+    // create toggle button
+    var tb = document.createElement("div");
+    tb.setAttribute("id","toggle_google_bars");
+
+    // styles
+    tb.style.background = "url('https://ssl.gstatic.com/ui/v1/zippy/arrow_down.png') no-repeat center #f2f2f2";
+    tb.style.height = "8px";
+    tb.style.width = "100%";
+    gb.style.display = "none";
+
+    // insert toggle button after google bars
+    gb.parentNode.insertBefore(tb, gb.nextSibling);
+
+    // add callback
+    tb.addEventListener("click", function() {
+        var gb = document.getElementById("gb");
+        var tb = document.getElementById("toggle_google_bars");
+        if (gb && (gb.style.display == "block")) {
+            gb.style.display = "none";
+            tb.style.MozTransform = "rotate(0deg)";
+        } else {
+            gb.style.display = "block";
+            tb.style.MozTransform = "rotate(180deg)";
+        }
+        return false;
+    }, false);
+
+    return;
 }
 
-document.addEventListener('DOMNodeInserted',hideBars,false);
+// wait until google bars appear, check every second
+setTimeout(addToggleButton, 1000);
+window.triedToAddToggleButton = 0;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.