-
Notifications
You must be signed in to change notification settings - Fork 34
/
PossibleVandalismEditsHelper.user.js
118 lines (105 loc) · 3.53 KB
/
PossibleVandalismEditsHelper.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
// ==UserScript==
// @name Possible Vandalism Edits Helper
// @description Display revision count and post age
// @homepage https://github.com/samliew/SO-mod-userscripts
// @author Samuel Liew
// @version 3.1.13
//
// @match https://*.stackoverflow.com/admin/dashboard?flagtype=postvandalismeditsauto*
// @match https://*.serverfault.com/admin/dashboard?flagtype=postvandalismeditsauto*
// @match https://*.superuser.com/admin/dashboard?flagtype=postvandalismeditsauto*
// @match https://*.askubuntu.com/admin/dashboard?flagtype=postvandalismeditsauto*
// @match https://*.mathoverflow.net/admin/dashboard?flagtype=postvandalismeditsauto*
// @match https://*.stackapps.com/admin/dashboard?flagtype=postvandalismeditsauto*
// @match https://*.stackexchange.com/admin/dashboard?flagtype=postvandalismeditsauto*
// @match https://stackoverflowteams.com/c/*/admin/dashboard?flagtype=postvandalismeditsauto*
//
// @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';
// This is a moderator-only userscript
if (!isModerator()) return;
const apikey = 'ENmQ1YxlYnp725at*EkjEg((';
// Append styles
addStylesheet(`
.post-header,
.post-summary,
.close-question-button,
.undelete-post,
.delete-post,
p[title="question originally asked"],
.user-action-time,
.mod-audit-user-info + br,
.js-post-flag-group > .d-flex > .flex--item:last-child {
display: none !important;
}
.post-list {
margin: 10px 0;
list-style: none;
}
.post-list li {
margin-bottom: 2px;
}
.revision-comment {
position: relative;
display: flex;
}
.revision-comment:hover {
background-color: transparent;
}
.info-num {
display: inline-block;
min-width: 18px;
margin-right: 10px;
font-weight: bold;
font-size: 1.1em;
}
.info-num.red {
color: var(--red-500);
}
.post-recommendation {
display: block;
margin: 5px 0;
font-weight: bold;
font-size: 1.2em;
}
.post-recommendation:before {
content: 'Recommendation: ';
}
.tagged-ignored {
opacity: 1;
}
`); // end stylesheet
// On script run
(async function init() {
// Move flagged post to post-list
$('.js-flagged-post').each(function() {
const link = $(this).find('.answer-hyperlink, .question-hyperlink').first().clone();
link.removeClass();
$(this).find('.flag-action-card-text ul.post-list').prepend(`<li><span class="revision-comment">${link[0].outerHTML}</span></li>`)
});
const flaggedPosts = $('.post-list a').each(function() {
this.dataset.postId = getPostId(this.href);
this.target = '_blank';
});
const postIds = flaggedPosts.map((_i, v) => v.dataset.postId).get();
const postsData = await getPostsFromApi(postIds);
// Add post info to each link
flaggedPosts.each(function (_i, link) {
const postData = postsData.find(v => v.post_id == link.dataset.postId);
if (!postData) return;
const age = Math.floor((Date.now() - postData.creation_date * 1000) / MS.oneDay);
$(link).before(`<span class="info-num post-age ${age > 365 ? 'red' : ''}" title="post age">${age}d</span>`);
});
})();