Hide Twitch SideBar

hide twitch sidebar

// ==UserScript==
// @name         Hide Twitch SideBar
// @version      1.8.2
// @description  hide twitch sidebar
// @author       raianwz
// @match        https://www.twitch.tv/*
// @exclude      *://player.twitch.tv/*
// @exclude      *://*.twitch.tv/p/*
// @exclude      *://*.twitch.tv/jobs/*
// @exclude      *://*.twitch.tv/subs/*
// @exclude      *://*.twitch.tv/embed/*
// @exclude      *://*.twitch.tv/store/*
// @exclude      *://*.twitch.tv/teams/*
// @exclude      *://*.twitch.tv/turbo/*
// @exclude      *://*.twitch.tv/popout/*
// @exclude      *://*.twitch.tv/moderator/*
// @exclude      *://*.twitch.tv/broadcast/*
// @exclude      *://*.twitch.tv/*/squad
// @exclude      *://*.twitch.tv/downloads*
// @icon         https://i.imgur.com/0GDybrZ.png
// @run-at       document-end
// @license      MIT
// @namespace    https://greasyfork.org/users/425245
// ==/UserScript==
let getElement = (e) => document.querySelector(e);
let url = window.location.href, count=0;
document.addEventListener('readystatechange', e => { e.target.readyState === "complete" ? CheckBar() : false});
function CheckBar(){ if(count >= 3) return; else if(!getElement('#btnSideBar')){LoadBar();count++;}}
function LoadBar(){
const navSidebar = getElement(`[data-a-target="side-nav-bar-collapsed"]`) ?? getElement(`.side-nav--expanded`);
const getBtnHideSide = localStorage.getItem('hidesdbar');
const setBtnHideSide= (value) => localStorage.setItem('hidesdbar',value);
!navSidebar ? CheckBar() : false
navSidebar.style.display="block"
hideSideBar(navSidebar)
    if(!getBtnHideSide){ setBtnHideSide(false)}
    else if(getBtnHideSide === 'true') {changeSide(navSidebar);}
    function hideSideBar(navSidebar){
        let where = getElement('div.Layout-sc-1xcs6mc-0.jDgJoG');
        const arrow = `<div class="Layout-sc-1xcs6mc-0 czRfnU"><div class="Layout-sc-1xcs6mc-0 cafndC"><div class="Layout-sc-1xcs6mc-0 khglzT"><div class="InjectLayout-sc-1i43xsx-0 kBtJDm"><button id="btnSideBar" class="ScCoreButton-sc-ocjdkq-0 ljgEdo ScButtonIcon-sc-9yap0r-0 eSFFfM">
        <div class="ButtonIconFigure-sc-1emm8lf-0 buvMbr"><div class="ScFigure-sc-wkgzod-0 fewniq tw-svg"> <svg width="20" height="20" viewBox="0 0 20 20"><g id="pArrow"><path fill-rule="evenodd" d="M16 16V4h2v12h-2zM6 9l2.501-2.5-1.5-1.5-5 5 5 5 1.5-1.5-2.5-2.5h8V9H6z"></path></g></svg></div></div></button></div></div></div></div>`;
        where.insertAdjacentHTML("beforeBegin",`${arrow}`)
        getElement('#btnSideBar').addEventListener("click", () => { changeSide(navSidebar) })
    }
    function changeSide(navSidebar){
        let pArrow = getElement('#pArrow');
        let sideR = `<path d="M4 16V4H2v12h2zM13 15l-1.5-1.5L14 11H6V9h8l-2.5-2.5L13 5l5 5-5 5z">`
        let sideL = `<path d="M16 16V4h2v12h-2zM6 9l2.501-2.5-1.5-1.5-5 5 5 5 1.5-1.5-2.5-2.5h8V9H6z">`
        if(navSidebar.style.display == "none"){navSidebar.style.display = "block" ; pArrow.innerHTML = `${sideL}`; setBtnHideSide(false);}
        else {navSidebar.style.display = "none" ; pArrow.innerHTML = `${sideR}`; setBtnHideSide(true);}
    }
    console.log('[DEBUG] %cHide Twitch SideBar is enabled','color:#19d404')
}