-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathuserchanger.js
88 lines (80 loc) · 2.91 KB
/
userchanger.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
// Voeg een nieuw inputveld toe zonder de originele inhoud te verwijderen ( thx voor de geen info lukas >:( )
if (window.location.href.includes("module=Profile")) {
var container = document.getElementById("smscMainBlockContainer");
container?.insertAdjacentHTML('beforeend', '<div id=inputVakContainter><input type="text" color="red" id="inputVak" placeholder="Custom name"></div>')
}
let config = get_config();
if (config.username_override == undefined) {
config.username_override = null;
set_config(config);
}
function getDefaultUserName() {
return document.querySelector(".js-btn-profile .hlp-vert-box span").innerText
}
let username_override = config.username_override;
if (username_override == null) {
username_override = getDefaultUserName();
config.username_override = username_override
set_config(config)
}
let full_unheading = true;
function change_lname(new_name) {
let name_element = document.querySelector(".js-btn-profile .hlp-vert-box span");
if (name_element !== null) {
let orig_name = name_element.innerText;
if (new_name !== null) {
name_element.innerText = new_name;
}
return orig_name;
}
return "Mr. Unknown";
}
function try_attach_messages_observer(orig_name, new_name) {
let messages_list = document.getElementById("msglist");
if (messages_list == null) {
return;
}
const observer = new MutationObserver(function (muts, observer) {
let in_send_messages_page = document.querySelector(".msgcell__head__title").innerText == "Verzonden";
for (const mut of muts) {
for (const msg of mut.addedNodes) {
if (msg.nodeName == "#text") { continue; }
let name_el = msg.querySelector(".modern-message__name");
if (name_el == null) { continue; }
let name_is_user = name_el.innerText.startsWith(orig_name);
if (name_is_user) {
if (new_name !== null) {
name_el.innerText = new_name;
}
}
if (name_is_user || in_send_messages_page) {
msg.querySelector(".modern-message__image img").src = getPfpLink(get_config().username_override);
}
}
}
});
observer.observe(messages_list, { attributes: false, childList: true, subtree: false });
}
function unhead_fully() {
let style_el = document.createElement("style");
style_el.innerText = `
.studentPicture, .rounded_profile_photo, .square_photo_64 {
display: none;
}
`;
document.head.appendChild(style_el);
}
let orig_name = change_lname(username_override, null);
try_attach_messages_observer(orig_name, username_override);
if (full_unheading) {
unhead_fully();
}
let input_vak = document.getElementById("inputVak")
input_vak?.addEventListener('input', function () {
var inputValue = input_vak.value;
inputValue = inputValue == "" ? null : inputValue;
config.username_override = inputValue;
set_config(config);
if (inputValue == null) { inputValue = orig_name }
change_lname(inputValue);
})