-
Notifications
You must be signed in to change notification settings - Fork 34
/
FindUsersAdditionalInfo.user.js
180 lines (163 loc) · 5.4 KB
/
FindUsersAdditionalInfo.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
// ==UserScript==
// @name Find Users Additional Info
// @description Loads more user details from the API on the find users page (/admin/find-users)
// @homepage https://github.com/samliew/SO-mod-userscripts
// @author Samuel Liew
// @version 2.0.13
//
// @match https://*.stackoverflow.com/admin/find-users*
// @match https://*.serverfault.com/admin/find-users*
// @match https://*.superuser.com/admin/find-users*
// @match https://*.askubuntu.com/admin/find-users*
// @match https://*.mathoverflow.net/admin/find-users*
// @match https://*.stackapps.com/admin/find-users*
// @match https://*.stackexchange.com/admin/find-users*
// @match https://stackoverflowteams.com/c/*/admin/find-users*
//
// @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 = 'vbWJDc*G3ug1FpRrCx0pEw((';
/*
// API: User
{
"answer_count": 123,
"question_count": 123,
"account_id": 1235467,
"last_modified_date": 1552884907,
"last_access_date": 1463183273,
"reputation": 123,
"creation_date": 1413755158,
"user_type": "registered",
"user_id": 1234567
}
*/
function getUsers(arrUids) {
return new Promise(function (resolve, reject) {
if (typeof arrUids === 'undefined' || arrUids === null || arrUids.length == 0) { reject(); return; }
$.get(`${seApiUrl}/users/${arrUids.join(';')}?pagesize=100&sort=reputation&site=${location.hostname}&filter=!BTeL)VYJZTHLffEZa-Pp0vhpUAyDVM&key=${apikey}`)
.done(function (data) {
resolve(data.items);
return;
})
.fail(reject);
});
}
// Append styles
addStylesheet(`
/* More space */
body > .container,
#left-sidebar + #content,
#content {
max-width: none !important;
width: 100% !important;
border: none;
}
#content br,
#left-sidebar {
display: none;
}
/* UI stuff */
.subheader {
text-align: center;
}
.subheader * {
float: none !important;
}
#content #find-users-form {
margin: 40px auto !important;
width: 40%;
text-align: center;
}
#content .s-notice {
text-align: center;
}
.js-usersearch-input,
.js-usersearch-submit {
height: 40px !important;;
margin: 0;
}
.js-usersearch-input {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
border-right: none;
margin-right: -1px;
}
.js-usersearch-submit {
border-top-left-radius: 0 !important;
border-bottom-left-radius: 0 !important;
padding: 3px 15px !important;
}
#users-list {
margin: 30px auto;
font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono';
}
#users-list thead th {
padding-bottom: 8px;
border-bottom: 2px solid black;
font-weight: bold;
}
#users-list tbody > tr:first-child td {
padding-top: 10px;
}
#users-list td,
#users-list th {
padding: 2px 5px;
}
#users-list tr th:nth-child(5),
#users-list tr td:nth-child(5) {
display: none;
}
#users-list td {
min-width: 70px;
max-width: 320px;
word-break: break-all;
}
#users-list td.align-right,
#users-list tbody td:first-child {
min-width: 30px;
text-align: right;
word-break: none;
}
`); // end stylesheet
// On script run
(function init() {
// UI stuff
const form = $('#content form').attr('id', 'find-users-form').removeClass('d-flex');
const searchField = $('input[name="q"]', form).addClass('s-input s-input__md js-usersearch-input');
const searchSubmit = $('button', form).addClass('s-btn s-btn__md s-btn__primary js-usersearch-submit').insertAfter(searchField);
searchField.parent().addClass('d-flex');
const table = $('#users-list');
const ids = table.find('tbody tr').find('a:first').attr('target', '_blank').each(function () {
$(this).closest('tr').attr('id', 'user-' + this.innerText);
}).get().map(v => Number(v.innerText));
// Add table headers
table.children('thead').children('tr').append(`<th>Network</th><th>Joined</th><th>Seen</th><th>Rep</th><th>UserType</th><th>Qns</th><th>Ans</th>`);
// Split API calls, max 100 per call
for (let i = 0; i < Math.ceil(ids.length / 100); i++) {
setTimeout(function (ids) {
getUsers(ids).then(function (users) {
users.forEach(function (user) {
const dateCreated = new Date(user.creation_date * 1000).toISOString().replace('T', ' ').replace(/:\d+\.\d+Z/, 'Z');
const dateLastSeen = new Date(user.last_access_date * 1000).toISOString().replace('T', ' ').replace(/:\d+\.\d+Z/, 'Z');
$('#user-' + user.user_id).append(`
<td class="align-right"><a href="https://stackexchange.com/users/${user.account_id}?tab=accounts" target="_blank">${user.account_id}</a></td>
<td>${dateCreated}</td><td>${dateLastSeen}</td><td class="align-right">${user.reputation}</td><td class="align-right">${user.user_type}</td><td class="align-right">${user.question_count}</td><td class="align-right">${user.answer_count}</td>`);
});
});
}, 10000 * i, ids.slice(i * 100, (i + 1) * 100));
}
})();