hide twitch sidebar
当前为
// ==UserScript==
// @name Hide Twitch SideBar
// @version 1.7.4
// @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/popout/*
// @exclude *://*.twitch.tv/moderator/*
// @exclude *://*.twitch.tv/broadcast/*
// @exclude *://*.twitch.tv/downloads*
// @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;
CheckBar();
function CheckBar(){ if(count >= 10) return; else if(!getElement('#btnSideBar')){setTimeout(()=>{LoadBar(); CheckBar(); count++;},5*1000);}}
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-nxg1ff-0.eMqFIm');
const arrow = `<div class="Layout-sc-nxg1ff-0 ccibQw"><div class="Layout-sc-nxg1ff-0 fXnqHq"><div class="Layout-sc-nxg1ff-0 hfhxmD"><div class="InjectLayout-sc-588ddc-0 ktQueN"><button id="btnSideBar" class="ScCoreButton-sc-1qn4ixc-0 ffyxRu ScButtonIcon-sc-o7ndmn-0 kqUZki"><div class="ButtonIconFigure-sc-1ttmz5m-0 fbCCvx"><div class="ScIconLayout-sc-1bgeryd-0 cXxJjc">
<div class="ScAspectRatio-sc-1sw3lwy-1 kPofwJ tw-aspect"><div class="ScAspectSpacer-sc-1sw3lwy-0 dsswUS"></div><svg width="100%" height="100%" version="1.1" viewBox="0 0 20 20" x="0px" y="0px" class="ScIconSVG-sc-1bgeryd-1 ifdSJl">
<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" clip-rule="evenodd"></path></g></svg></div></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:green');
}