forked from samliew/SO-mod-userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPossibleVandalismEditsHelper.user.js
112 lines (97 loc) · 3.26 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
// ==UserScript==
// @name Possible Vandalism Edits Helper
// @description Display revision count and post age
// @homepage https://github.com/samliew/SO-mod-userscripts
// @author @samliew
// @version 1.2
//
// @include https://*stackoverflow.com/admin/dashboard?flagtype=postvandalismeditsauto*
// @include https://*serverfault.com/admin/dashboard?flagtype=postvandalismeditsauto*
// @include https://*superuser.com/admin/dashboard?flagtype=postvandalismeditsauto*
// @include https://*askubuntu.com/admin/dashboard?flagtype=postvandalismeditsauto*
// @include https://*mathoverflow.net/admin/dashboard?flagtype=postvandalismeditsauto*
// @include https://*.stackexchange.com/admin/dashboard?flagtype=postvandalismeditsauto*
// ==/UserScript==
(function() {
'use strict';
// Moderator check
if(typeof StackExchange == "undefined" || !StackExchange.options || !StackExchange.options.user || !StackExchange.options.user.isModerator ) return;
function doPageload() {
$('.post-list .revision-comment a').each(function() {
const flag = $(this).parents('.flagged-post-row');
const link = $(this);
const pid = this.href.match(/\d+/)[0];
// Get post info
$.get({
url: `https://stackoverflow.com/posts/${pid}/timeline`,
success: function(data) {
const eventrows = $('.event-rows tr', data);
const dateCreated = new Date(eventrows.filter('[data-eventtype="history"]').last().find('.relativetime').attr('title'));
const dateDiff = Date.now() - dateCreated;
const age = Math.floor(dateDiff / 86400000); // 86400000 = 1 day
const revisions = eventrows.filter(function() {
return $(this).find('.event-verb').text().indexOf('edited') >= 0;
});
//console.log(eventrows, dateCreated, age, revisions.length);
link.before(`<span class="info-num rev-count ${revisions.length >= 5 ? 'red' : ''}" title="post revisions">${revisions.length}</span>`);
link.before(`<span class="info-num post-age ${age > 365 ? 'red' : ''}" title="post age">${age}d</span>`);
}
});
});
}
function appendStyles() {
const styles = `
<style>
.post-header,
.post-summary,
.close-question-button,
.undelete-post,
.delete-post,
p[title="question originally asked"],
.user-action-time,
.mod-audit-user-info + br {
display: none !important;
}
.post-list {
margin-left: 0;
}
.post-list .title-divider {
margin-top: 5px;
}
.revision-comment {
position: relative;
display: block;
}
.revision-comment:hover {
background: cornsilk;
}
.info-num {
display: inline-block;
min-width: 18px;
margin-right: 10px;
font-weight: bold;
font-size: 1.1em;
}
.info-num.red {
color: red;
}
.post-recommendation {
display: block;
margin: 5px 0;
font-weight: bold;
font-size: 1.2em;
}
.post-recommendation:before {
content: 'Recommendation: ';
}
.tagged-ignored {
opacity: 1;
}
</style>
`;
$('body').append(styles);
}
// On page load
appendStyles();
doPageload();
})();