forked from samliew/SO-mod-userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModUserQuicklinksEverywhere.user.js
136 lines (120 loc) · 4.26 KB
/
ModUserQuicklinksEverywhere.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
// ==UserScript==
// @name Mod User Quicklinks Everywhere
// @description Adds quicklinks to user infobox in posts
// @homepage https://github.com/samliew/SO-mod-userscripts
// @author Samuel Liew
// @version 4.1.13
//
// @match https://*.stackoverflow.com/*
// @match https://*.serverfault.com/*
// @match https://*.superuser.com/*
// @match https://*.askubuntu.com/*
// @match https://*.mathoverflow.net/*
// @match https://*.stackapps.com/*
// @match https://*.stackexchange.com/*
// @match https://stackoverflowteams.com/*
//
// @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, parentUrl */
/// <reference types="./globals" />
'use strict';
// This is a moderator-only userscript
if (!isModerator()) return;
const isChildMeta = typeof StackExchange !== 'undefined' && StackExchange.options?.site?.isChildMeta;
const showOnHover = false;
function addUserLinks() {
$('.post-user-info, .s-user-card, .user-details, .js-body-loader div.ai-center.fw-wrap')
.filter(function () {
// Do not add links to users in sidebar
return $(this).closest('#sidebar').length === 0;
})
.not('.js-mod-quicklinks')
.addClass('js-mod-quicklinks')
.find('a[href^="/users/"]:first').each(function () {
// Add Votes and IP-xref links after mod-flair if mod, or after the user link
const uid = Number(this.href.match(/-?\d+/));
const modFlair = $(this).next('.mod-flair');
if (uid == -1 || modFlair.length == 1) return;
const userlinks = `
<div class="somu-mod-userlinks ${showOnHover ? 'show-on-hover' : ''}">
<a target="_blank" href="${parentUrl}/users/account-info/${uid}" title="User Admin Page">mod</a>
<a target="_blank" href="/admin/users/${uid}/post-comments" title="All Comments by User">cmnts</a>
<a target="_blank" href="${parentUrl}/admin/show-user-votes/${uid}" title="Targeted Votes Tables">votes</a>
<a target="_blank" href="${parentUrl}/admin/xref-user-ips/${uid}?daysback=30&threshold=2" title="IP Activity Cross-Reference">xref</a>
<a target="_blank" href="${parentUrl}/admin/cm-message/create/${uid}?action=suspicious-voting" title="Compose CM Message (Suspicious Voting)" class="${isChildMeta ? 'd-none' : ''}">cm</a>
</div>`;
$(this).closest('.user-info, .s-user-card, .js-mod-quicklinks').append($(userlinks));
});
$('.user-info').addClass('js-mod-quicklinks');
}
// Append styles
addStylesheet(`
.user-info .user-details {
position: relative;
}
.somu-mod-userlinks {
display: flex;
white-space: nowrap;
font-size: 0.95em;
}
#questions .somu-mod-userlinks {
/* No quicklinks in question lists */
display: none;
}
.s-user-card .somu-mod-userlinks {
/* New s-user-card uses grid, we want it in last position */
order: 999;
grid-column-start: 2;
text-align: right;
}
.somu-mod-userlinks.show-on-hover {
display: none;
}
.somu-mod-userlinks,
.somu-mod-userlinks a,
.started .somu-mod-userlinks a {
color: var(--black-400);
}
.somu-mod-userlinks > a {
display: inline-block;
margin-right: 4px;
}
.somu-mod-userlinks a:hover,
.started .somu-mod-userlinks a:hover {
color: var(--black);
}
.post-user-info:hover .somu-mod-userlinks,
.user-info:hover .somu-mod-userlinks {
display: flex;
}
.flex--item + .somu-mod-userlinks {
position: initial !important;
display: inline-flex;
width: auto;
background: none;
margin-left: 4px;
margin-top: 1px;
}
/* review stats/leaderboard */
.stats-mainbar .task-stat-leaderboard .user-details {
line-height: inherit;
}
`); // end stylesheet
// On script run
(function init() {
$('.task-stat-leaderboard').removeClass('user-info');
addUserLinks();
// Page updates
$(document).ajaxStop(addUserLinks);
$(document).on('moduserquicklinks', addUserLinks);
})();