Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Discord Toggle Channels Bar
- // @namespace https://discordapp.com
- // @version 2.0
- // @description Adds show/hide channels sidebar button to Discord Web App
- // forked from https://github.com/mindovermiles262/discord-toggle-channels
- // @author v2.0 modified by Eter#3834
- // @match https://discord.com/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- // Classes of DIVs you want to be able to toggle sidebar
- const toggleButtons = [
- "children-19S4PO",
- "toggleChannelsBtn"
- ];
- const columnToHide = "sidebar-2K8pFh"
- const showHideSidebarButtonParentClass = "scroller-2TZvBN";
- //const showHideSidebarButtonParentClass = "wrapper-1Rf91z"; //top bar instead
- const roomDivClass = "containerDefault-1ZnADq";
- const unreadClass = "unread-3zKkbm";
- const channelsWidth = "240px";
- function sleep(ms) {
- return new Promise(resolve => setTimeout(resolve, ms));
- }
- async function pageload() {
- // Wait 5 seconds for page to load
- await sleep(5000);
- main()
- }
- const toggleVisibility = function() {
- let sidebar = document.getElementsByClassName(columnToHide)[0];
- sidebar.style.transition = "width 150ms ease-out";
- if (sidebar.style.width == "1px") {
- sidebar.style.width = channelsWidth;
- } else {
- sidebar.style.width = "1px";
- }
- }
- let cheveronDirection = function() {
- const sidebar = document.getElementsByClassName(columnToHide)[0]
- const btn = document.getElementById("dtcb-cheverons")
- if (sidebar.style.width == "1px") {
- btn.innerText = "βΊ"; // symbol for >
- } else {
- btn.innerText = "βΉ"; // symbol for <
- }
- }
- const createSidebarButton = function() {
- let btnDiv = document.createElement("div");
- btnDiv.setAttribute("class", "toggleChannelsBtn");
- btnDiv.setAttribute("id", "toggleChannelsBtn");
- btnDiv.style.width = "70px";
- btnDiv.style.color = "#FFFFFF";
- btnDiv.style.position = "absolute";
- btnDiv.style.top = "0";
- let btn = document.createElement("p");
- btn.setAttribute("id", "dtcb-cheverons");
- btn.innerText = "βΉ"; // symbol for <
- btn.style.margin = "0";
- btn.style.cursor = "pointer";
- //btn.style.backgroundColor = "#36393f";
- btn.style.color = "#8e9297";
- btn.style.display = "inline-flex";
- btn.style.padding = "0px 6px 4px";
- btn.style.justifyContent = "center";
- btn.style.borderBottomRightRadius = "10px";
- btn.style.fontSize = "15px";
- btnDiv.appendChild(btn);
- return btnDiv;
- }
- const addListenersToToggleButtons = function() {
- toggleButtons.forEach(function(elem) {
- document.getElementsByClassName(elem)[0].addEventListener('click', function() {
- toggleVisibility();
- cheveronDirection();
- })
- });
- }
- const autohideSidebar = function() {
- const roomDivs = document.getElementsByClassName(roomDivClass)
- Array.from(roomDivs).forEach(function(room) {
- room.addEventListener('click', function() {
- toggleVisibility();
- cheveronDirection();
- })
- })
- }
- const main = function() {
- console.log("[*] Loading Discord Toggle Channenels Bar Userscript");
- const newBtn = createSidebarButton()
- document.getElementsByClassName(showHideSidebarButtonParentClass)[0].appendChild(newBtn)
- addListenersToToggleButtons();
- autohideSidebar();
- }
- pageload();
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement