-
Notifications
You must be signed in to change notification settings - Fork 2
/
Prolix.user.js
176 lines (147 loc) · 4.42 KB
/
Prolix.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// ==UserScript==
// @name Prolix
// @description Improve site UX for particularly long-winded users and their allies.
// @version 0.6.5
// @author Cody Gray
// @homepage https://github.com/codygray/so-userscripts
// @namespace https://github.com/codygray/so-userscripts/
// @updateURL https://github.com/codygray/so-userscripts/raw/master/Prolix.user.js
// @downloadURL https://github.com/codygray/so-userscripts/raw/master/Prolix.user.js
// @supportURL https://github.com/codygray/so-userscripts/issues
//
// @include https://*stackoverflow.com/*
// @include https://*serverfault.com/*
// @include https://*superuser.com/*
// @include https://*askubuntu.com/*
// @include https://*mathoverflow.net/*
// @include https://*.stackexchange.com/*
//
// @exclude *chat.*
// @exclude *blog.*
// ==/UserScript==
(function()
{
'use strict';
const IS_META = (location.hostname === 'meta.stackoverflow.com' || StackExchange?.options?.site?.parentUrl);
function onElementInserted(containerSelector, elementSelector, callback)
{
const MutationObserver = (window.MutationObserver || window.WebKitMutationObserver);
const observer = new MutationObserver((mutations) =>
{
mutations.forEach((mutation) =>
{
mutation.addedNodes.forEach((node) =>
{
$(node).find(elementSelector).each((i, element) =>
{
callback(element);
});
});
});
});
const config = { childList: true, subtree: true };
$(containerSelector).each((i, element) =>
{
observer.observe(element, config);
});
}
function resizeCommentTextarea(element)
{
const styles = window.getComputedStyle(element) || element.currentStyle;
const marginT = parseInt(styles.marginTop);
const marginB = parseInt(styles.marginBottom);
if (element.scrollHeight > element.clientHeight)
{
element.style.height = `${element.scrollHeight + marginT + marginB}px`;
}
}
function onPageLoad()
{
// Make all comment textareas auto-expand vertically to fit their text, both upon
// initial appearance (e.g., clicking "edit") and when composing as lines of text
// are added that overflow the currently visible area.
onElementInserted('.js-comments-container', 'textarea[name="comment"].js-comment-text-input', (textarea) =>
{
resizeCommentTextarea(textarea);
textarea.addEventListener('input', () =>
{
resizeCommentTextarea(textarea);
});
});
}
function appendStyles()
{
const styles = `
<style>
/* REMOVE CLUTTER: */
/* Remove the "Products" menu in the Stack Overflow top nav bar.
* <https://meta.stackoverflow.com/q/386393> */
.top-bar .-marketing-link,
header.s-topbar .s-navigation
{
display: none !important;
}
/* Hide ad banners */
#mainbar .question .js-zone-container
{
display: none;
}
/* UNSTICKY TOP BAR: */
html
{
--top-bar-allocated-space: 0;
}
body
{
padding-top: 0;
}
header.top-bar,
body.channels-page header.top-bar,
header.s-topbar
{
position: initial !important;
}
/* GENERAL: */
/* Make visited links visible again by changing them to a distinct color (e.g., purple).
* <https://meta.stackoverflow.com/q/392188> */
body .post-text a:not(.post-tag):not(.badge-tag):visited,
body .comment-copy a:visited,
body .wmd-preview a:not(.post-tag):not(.badge-tag):visited,
body .question-hyperlink:visited,
body .answer-hyperlink:visited,
.s-post-summary--content .s-post-summary--content-title a:visited
{
color: ${IS_META ? '#848586' : '#5C08C3'};
}
/* VOTING CONTAINER: */
/* Make voting arrows and other sidebar content "sticky", so that it scrolls with long posts. */
.votecell .js-voting-container
{
position: sticky;
top: 0;
z-index: 100;
}
/* POST QUICK-LINKS: */
/* Hide the "follow" link. */
.js-post-menu .s-anchors > .flex--item .js-follow-post
{
display: none;
}
/* COMMENTS: */
/* Undo stupid Stacks style that hides the scrollbar arrows. */
.s-input, .s-textarea
{
scrollbar-color: inherit !important;
}
/* Since this textarea is auto-expanding, no need for scrollbar arrows. */
.comment-form textarea.js-comment-text-input
{
overflow: hidden;
}
</style>
`;
document.documentElement.insertAdjacentHTML('beforeend', styles);
}
appendStyles();
onPageLoad();
})();