-
Notifications
You must be signed in to change notification settings - Fork 34
/
CommentFlagTypeColours.user.js
201 lines (185 loc) · 7.02 KB
/
CommentFlagTypeColours.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// ==UserScript==
// @name Comment Flag Type Colours
// @description Background colours for each comment flag type
// @homepage https://github.com/samliew/SO-mod-userscripts
// @author Samuel Liew
// @version 4.0.13
//
// @match https://*.stackoverflow.com/questions/*
// @match https://*.serverfault.com/questions/*
// @match https://*.superuser.com/questions/*
// @match https://*.askubuntu.com/questions/*
// @match https://*.mathoverflow.net/questions/*
// @match https://*.stackapps.com/questions/*
// @match https://*.stackexchange.com/questions/*
// @match https://stackoverflowteams.com/c/*/questions/*
//
// @match https://*.stackoverflow.com/posts/*/timeline*
// @match https://*.serverfault.com/posts/*/timeline*
// @match https://*.superuser.com/posts/*/timeline*
// @match https://*.askubuntu.com/posts/*/timeline*
// @match https://*.mathoverflow.net/posts/*/timeline*
// @match https://*.stackapps.com/posts/*/timeline*
// @match https://*.stackexchange.com/posts/*/timeline*
// @match https://stackoverflowteams.com/c/*/posts/*/timeline*
//
// @match https://*.stackoverflow.com/admin/dashboard*
// @match https://*.serverfault.com/admin/dashboard*
// @match https://*.superuser.com/admin/dashboard*
// @match https://*.askubuntu.com/admin/dashboard*
// @match https://*.mathoverflow.net/admin/dashboard*
// @match https://*.stackapps.com/admin/dashboard*
// @match https://*.stackexchange.com/admin/dashboard*
// @match https://stackoverflowteams.com/c/*/admin/dashboard*
//
// @match https://*.stackoverflow.com/users/flag-summary/*?group=4*
// @match https://*.serverfault.com/users/flag-summary/*?group=4*
// @match https://*.superuser.com/users/flag-summary/*?group=4*
// @match https://*.askubuntu.com/users/flag-summary/*?group=4*
// @match https://*.mathoverflow.net/users/flag-summary/*?group=4*
// @match https://*.stackapps.com/users/flag-summary/*?group=4*
// @match https://*.stackexchange.com/users/flag-summary/*?group=4*
// @match https://stackoverflowteams.com/c/*/users/flag-summary/*?group=4*
//
// @match https://*.stackoverflow.com/admin/users/*/post-comments*
// @match https://*.serverfault.com/admin/users/*/post-comments*
// @match https://*.superuser.com/admin/users/*/post-comments*
// @match https://*.askubuntu.com/admin/users/*/post-comments*
// @match https://*.mathoverflow.net/admin/users/*/post-comments*
// @match https://*.stackapps.com/admin/users/*/post-comments*
// @match https://*.stackexchange.com/admin/users/*/post-comments*
// @match https://stackoverflowteams.com/c/*/admin/users/*/post-comments*
//
// @exclude */admin/dashboard?flagtype=answerduplicateanswerauto*
// @exclude */admin/dashboard?flagtype=commentvandalismdeletionsauto*
// @exclude */admin/dashboard?flagtype=commenttoomanydeletedrudenotconstructiveauto*
//
// @exclude https://api.stackexchange.com/*
// @exclude https://data.stackexchange.com/*
// @exclude https://contests.stackoverflow.com/*
// @exclude https://winterbash*.stackexchange.com/*
// @exclude *chat.*
// @exclude *blog.*
// @exclude */tour
//
// @require https://raw.githubusercontent.com/samliew/SO-mod-userscripts/master/lib/se-ajax-common.js
// @require https://raw.githubusercontent.com/samliew/SO-mod-userscripts/master/lib/common.js
// ==/UserScript==
/* globals StackExchange */
/// <reference types="./globals" />
'use strict';
// Append styles
addStylesheet(`
.ctype-bad,
.ctype-poor,
.ctype-poor-bot,
.ctype-meh {
display: inline;
padding: 2px 5px 3px !important;
line-height: 1;
font-size: 10px;
font-style: normal;
border-radius: 2px;
color: white;
text-shadow: 0px 0px 1px #666;
}
.ctype-bad {
background-color: var(--red-500);
}
.ctype-poor {
background-color: var(--orange-400);
}
.ctype-poor-bot {
background-color: var(--orange-300);
}
.ctype-meh {
background-color: var(--black-300);
}
.ctype-custom {
padding: 2px 0 !important;
background-color: var(--yellow-100);
line-height: inherit;
color: var(--black);
}
.comment-flag-off {
color: var(--black-500);
}
`); // end stylesheet
// On script run
(function init() {
// Path /post-comments
if (location.pathname.indexOf('/post-comments') > 0) {
// wrap comment type text with .revision-comment span
$('.deleted-info').html((i, html) => html.replace(/span>\s*([a-z]+(\s[a-z]+)*)\s/i, `><span class="revision-comment">$1</span> `));
}
// New stacks theme
if (document.body.classList.contains('unified-theme')) {
// wrap comment type text with .revision-comment span
$('.js-flagged-comment .js-flag-text').html((i, html) => html.replace(/^(.*) - </i, `<span class="revision-comment">$1</span> - <`));
}
// On Post Timelines, highlight differently
if (/^\/posts\/\d+\/timeline.*/.test(location.pathname)) {
$('.event-verb span').filter((i, el) => el.children.length == 0).each(function (i, el) {
let cls = '';
el.innerText = el.innerText.trim();
switch (el.innerText.toLowerCase()) {
case 'commentrudeoroffensive':
case 'rudeoroffensive':
cls = 'ctype-bad';
break;
case 'commentunwelcoming':
case 'unwelcoming':
cls = 'ctype-poor';
break;
case 'commentnolongerneeded':
case 'nolongerneeded':
cls = 'ctype-meh';
break;
case 'commentother':
case 'other':
cls = 'ctype-custom';
break;
}
if (cls !== '') el.classList.add(cls);
if (cls == 'ctype-custom') {
$(el).closest('.event-verb').siblings('.event-comment').find('span').addClass('ctype-custom');
}
});
return false;
}
// All other included pages
$('.revision-comment').filter(function () {
// Not in a mod post list and table cell, or not the first element
return ($(this).closest('ul.post-list').length == 0 && $(this).parent('td').length == 0) || $(this).index() !== 0;
}).each(function (i, el) {
let cls = 'ctype-custom';
el.innerText = el.innerText.trim();
switch (el.innerText.toLowerCase()) {
case 'rude or offensive':
case 'harassment, bigotry, or abuse':
case 'harrassment, bigotry, or abuse':
cls = 'ctype-bad';
break;
case 'unfriendly or unkind (auto)':
case 'robot says unfriendly':
cls = 'ctype-poor-bot';
break;
case 'unfriendly or unkind':
case 'unwelcoming':
cls = 'ctype-poor';
break;
case 'no longer needed':
case 'not relevant':
case 'not constructive':
case 'obsolete':
case 'not constructive or off topic':
case 'too chatty':
cls = 'ctype-meh';
break;
}
el.classList.add(cls);
if (cls == 'ctype-custom') {
$(el).parents('.deleted-info').next('.flag-other-text').addClass('revision-comment ctype-custom');
}
});
})();