forked from lg188/volafile-scripts
-
Notifications
You must be signed in to change notification settings - Fork 2
/
volafile-name-to-chat.user.js
45 lines (32 loc) · 1.21 KB
/
volafile-name-to-chat.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
// ==UserScript==
// @name Volafile Name to Chat
// @namespace volafile.name.to.chat
// @description Click a name in chat and it will appear in the chat input.
// @include https://volafile.org/r/*
// @match https://volafile.org/r/*
// @version 2
// @grant none
// ==/UserScript==
var separator = ", ";
var chat = document.getElementById("chat_input");
var observer = new MutationObserver(function(mutations){
mutations.forEach(function(mutation){
for(j = 0; j < mutation.addedNodes.length; j++){
var username_element = mutation.addedNodes[j].children[0];
username_element.href = "javascript:";
username_element.target = "";
var children = username_element.childNodes;
for(var i = 0; i < children.length; i++) {
if(children[i].tagName !== "SPAN" && children[i].textContent !== ":") {
var name = children[i].textContent;
var name_element = children[i];
}
}
username_element.addEventListener("click", function() {
chat.focus();
chat.value = name + separator + chat.value;
}, true);
}
});
});
observer.observe(document.querySelector('#chat_messages'), {childList: true});