-
Notifications
You must be signed in to change notification settings - Fork 34
/
UserProfileLinks.user.js
112 lines (103 loc) · 3.59 KB
/
UserProfileLinks.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 User Profile Links
// @description Expands user network links menu and add chat profile links
// @homepage https://github.com/samliew/SO-mod-userscripts
// @author Samuel Liew
// @version 2.0.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 */
/// <reference types="./globals" />
'use strict';
// This is a moderator-only userscript
if (!isModerator()) return;
// Check if profile menu exists
const isUserPage = document.body.classList.contains('user-page');
const profilesMenu = document.getElementById('profiles-menu');
if (!isUserPage || !profilesMenu) {
console.log('User network profile dropdown not found.');
return;
}
// Add class to parent wrapper
const wrapper = profilesMenu.parentElement;
wrapper.id = 'profiles-wrapper';
// Add chat profile links to menu
const list = profilesMenu.querySelector('ul');
const links = list.querySelectorAll('a');
const aid = Number(links[links.length - 1].getAttribute('href').match(/\/users\/(\d+)\//)[1]); // user account id
list.innerHTML += `
<li class="s-menu--divider"></li>
<li role="menuitem">
<a href="https://chat.stackoverflow.com/accounts/${aid}" title="Stack Overflow chat profile" class="s-block-link d-flex ai-center ws-nowrap d-flex ai-center">
<div class="favicon favicon-stackoverflow site-icon mr4"></div>
Chat.SO
</a>
</li>
<li role="menuitem">
<a href="https://chat.stackexchange.com/accounts/${aid}" title="Stack Exchange chat profile" class="s-block-link d-flex ai-center ws-nowrap d-flex ai-center">
<div class="favicon favicon-stackexchange site-icon mr4"></div>
Chat.SE
</a>
</li>
<li role="menuitem">
<a href="https://chat.meta.stackexchange.com/accounts/${aid}" title="Meta Stack Exchange chat profile" class="s-block-link d-flex ai-center ws-nowrap d-flex ai-center">
<div class="favicon favicon-stackexchangemeta site-icon mr4"></div>
Chat.MSE
</a>
</li>`;
// Append styles
const styles = document.createElement('style');
styles.setAttribute('data-somu', GM_info?.script.name);
styles.innerHTML = `
#profiles-wrapper button[aria-controls="profiles-menu"] {
display: none;
}
#profiles-wrapper {
align-items: flex-start !important;
margin: 0 !important;
}
#profiles-menu {
display: block !important;
position: static;
max-width: none;
min-width: 10rem;
margin-left: 10px;
padding: 0 !important;
z-index: unset;
border-radius: unset;
border: unset;
background: var(--white);
box-shadow: unset;
white-space: nowrap;
}
#profiles-menu a.s-block-link {
padding: 3px !important;
}
#profiles-menu .iconLogoSEXxs.mr2 {
margin-right: 4px !important;
}
#profiles-menu .s-menu--title,
#profiles-menu .is-selected {
display: none !important;
}
`;
document.body.appendChild(styles);