// ==UserScript== // @name Overleaf Collapse All Folders // @namespace http://itmunk.dk // @version 2.0 // @description Adds a button, that when pressed, collapses all folders within the Overleaf file viewer. // @author Andreas Poulsen (@supercigar) // @match https://www.overleaf.com/project/* // @icon https://cdn.overleaf.com/img/ol-brand/overleaf_og_logo.png // @grant none // @downloadURL https://update.greasyfork.icu/scripts/425122/Overleaf%20Collapse%20All%20Folders.user.js // @updateURL https://update.greasyfork.icu/scripts/425122/Overleaf%20Collapse%20All%20Folders.meta.js // ==/UserScript== 'use strict'; addCollapseAllButton(); // Wait for toolbar to load, in order to add new button function addCollapseAllButton(){ var intv = setInterval(function() { var toolbarFiletree = document.getElementsByClassName("toolbar-filetree"); // Return false until toolbar-filetree is found if(toolbarFiletree.length < 1){ return false; } //when element is found, clear the interval. clearInterval(intv); var toolbarHalf = toolbarFiletree[0].firstElementChild; var compressBtn = toolbarHalf.firstElementChild.cloneNode(true); var label = compressBtn.firstElementChild; var span = label.nextElementSibling; label.className = "fa fa-arrow-up"; span.innerText = "Collapse All"; compressBtn.onclick = collapseAll; toolbarHalf.appendChild(compressBtn); }, 100); } // Get a list of