Skip to content

Instantly share code, notes, and snippets.

@elken
Created September 22, 2022 20:30
Show Gist options
  • Save elken/4c1cc49ae107ac91797eb0d6d812544a to your computer and use it in GitHub Desktop.
Save elken/4c1cc49ae107ac91797eb0d6d812544a to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Toggle Sidebar
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @license MIT
// @match https://discord.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=discord.com
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
waitForKeyElements (".scroller-3X7KbA", setupToggle);
function toggleSidebar() {
const sidebar = document.querySelector(`.sidebar-1tnWFu`);
sidebar.style.display = ["", "flex"].includes(sidebar.style.display) ? "none" : "flex";
}
function setupToggle(node) {
node.after(`
<div class="listItem-3SmSlK">
<div class="actionButton-3-B2x-" style="width: 48px;height: 48px;">
<svg id="toggleSidebar" class="icon-1WVg4I" width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--! Font Awesome Pro 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path fill="currentColor" d="M32 64c17.7 0 32 14.3 32 32l0 320c0 17.7-14.3 32-32 32s-32-14.3-32-32V96C0 78.3 14.3 64 32 64zm214.6 73.4c12.5 12.5 12.5 32.8 0 45.3L205.3 224l229.5 0-41.4-41.4c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l96 96c12.5 12.5 12.5 32.8 0 45.3l-96 96c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L434.7 288l-229.5 0 41.4 41.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0l-96-96c-12.5-12.5-12.5-32.8 0-45.3l96-96c12.5-12.5 32.8-12.5 45.3 0zM640 96V416c0 17.7-14.3 32-32 32s-32-14.3-32-32V96c0-17.7 14.3-32 32-32s32 14.3 32 32z"/></svg>
</div>
</div>`);
document.getElementById("toggleSidebar").addEventListener('click', toggleSidebar);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment