-
Notifications
You must be signed in to change notification settings - Fork 1
/
_global-resize-sidebar.user.js
94 lines (82 loc) · 2.51 KB
/
_global-resize-sidebar.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// ==UserScript==
// @name Global - resize sidebar
// @description Adds the ability to resize sidebars
// @version 1.0
// @author me
//
// @namespace https://github.com/ricewind012/userstyles
// @downloadURL https://github.com/ricewind012/userstyles/raw/master/_global-resize-sidebar.user.js
// @updateURL https://github.com/ricewind012/userstyles/raw/master/_global-resize-sidebar.user.js
//
// @match https://developer.mozilla.org/*
// @match https://boards.4channel.org/*
// @match https://boards.4chan.org/*
// @match https://old.reddit.com/*
// @match https://soundcloud.com/*
// @match https://searchfox.org/*
// @match https://discord.com/*
// @match https://github.com/*
//
// @match https://nitter.net/*
// @match https://nitter.unixfox.eu/*
// @match https://nitter.namazso.eu/*
//
// @match https://stackexchange.com/*
// @match https://stackoverflow.com/*
// @match https://superuser.com/*
// @match https://askubuntu.com/*
//
// @match https://safebooru.org/*
// @match https://yande.re/*
//
// @match https://wikipedia.org/*
// @include /^https?://wiki\./
//
// @grant GM_addStyle
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_addValueChangeListener
// ==/UserScript==
function SetSidebarWidth(nWidth) {
document.body.setAttribute(
'style',
`--sidebar-width: clamp(20vw, ${nWidth}px), 50vw);`
);
}
const k_strSmallScreen = '768px';
let elSeparator = document.createElement('div');
elSeparator.id = '-sidebar-separator';
document.body.appendChild(elSeparator);
GM_addStyle(`
#-sidebar-separator {
position: fixed;
left: calc(var(--sidebar-width) - var(--sidebar-separator-width) / 2);
top: var(--header-h);
right: auto;
bottom: 0;
z-index: 999;
width: var(--sidebar-separator-width);
cursor: ew-resize;
@media (max-width: ${k_strSmallScreen}) {
display: none;
}
}
`);
let nSidebarWidth = GM_getValue('sidebar-width');
if (nSidebarWidth);
SetSidebarWidth(nSidebarWidth);
GM_addValueChangeListener(
'sidebar-width',
(strName, nOldValue, nNewValue, bRemote) => SetSidebarWidth(nNewValue)
);
elSeparator.addEventListener('pointerdown', () => {
function fnMove(ev) {
GM_setValue('sidebar-width', ev.pageX);
}
function fnUp() {
removeEventListener('pointermove', fnMove);
removeEventListener('pointerup', fnUp);
}
addEventListener('pointermove', fnMove, { passive: true });
addEventListener('pointerup', fnUp, { passive: true });
});