-
Notifications
You must be signed in to change notification settings - Fork 1
/
reddit-side-bar-max-width.user.js
58 lines (53 loc) · 2.01 KB
/
reddit-side-bar-max-width.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// ==UserScript==
// @name Old Reddit Side Bar toggle and max width
// @namespace https://github.com/Alistair1231/my-userscripts/
// @version 0.1.0
// @description limits the width of the side bar to 20vw, adds a button to toggle the sidebar and auto-hides the sidebar if the window width is less than 1200px
// @downloadURL https://github.com/Alistair1231/my-userscripts/raw/master/reddit-side-bar-max-width.user.js
// @author Alistair1231
// @match https://old.reddit.com/*
// @icon https://icons.duckduckgo.com/ip2/github.com.ico
// @grant GM.addStyle
// @license MIT
// ==/UserScript==
// https://github.com/Alistair1231/my-userscripts/raw/master/reddit-side-bar-max-width.user.js
(() => {
GM.addStyle(`
.side {
max-width: 20vw;
}
body {
margin: auto !important;
max-width: 1200px;
}
`);
// add display: none to sidebar if display width is less than 1000px
if (window.innerWidth < 1200) {
let sidebar = document.querySelector(".side");
sidebar.style.display = "none";
}
// Create a button
let sidebarToggle = document.createElement("a");
sidebarToggle.href = "#";
sidebarToggle.textContent = "sidebar";
sidebarToggle.className = "pref-lang choice";
// Add click event listener
sidebarToggle.addEventListener("click", () => {
let sidebar = document.querySelector(".side");
if (sidebar.style.display === "none") {
sidebar.style.display = "block";
} else {
sidebar.style.display = "none";
}
});
// add button after last separator in div#header-bottom-right
let headerBottomRight = document.querySelector("#header-bottom-right");
let separators = headerBottomRight.querySelectorAll(".separator");
let lastSeparator = separators[separators.length - 1];
lastSeparator.after(sidebarToggle);
// add new separator after button
let newSeparator = document.createElement("span");
newSeparator.textContent = "|";
newSeparator.className = "separator";
sidebarToggle.after(newSeparator);
})();