-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopypasta_script.js
103 lines (89 loc) · 3.23 KB
/
copypasta_script.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
var TextArea;
chatObserver = new MutationObserver(function(mutations){
mutations.forEach(function(mutation){
//this is so that the addon doesn't try to work before the chat has loaded
for(i=0; i<mutation.addedNodes.length; i++)
{
if(mutation.addedNodes[i].className === "ember-view chat-line admin" || mutation.addedNodes[i].className === "ember-view chat-line" ||
mutation.addedNodes[i].className === "chat-line admin" || mutation.addedNodes[i].className === "chat-line")
{
textArea = document.getElementsByClassName("ember-view ember-text-area mousetrap")[0];
linesObserver.observe(mutation.addedNodes[i].parentNode, {childList: true});
chatObserver.disconnect();
}
}
});
});
linesObserver = new MutationObserver(function(mutations){
mutations.forEach(function(mutation){
//observers will almost always return added nodes one node at a time, but just to be safe
for(k = 0; k<mutation.addedNodes.length; k++)
{
var isMessage = false;
if(mutation.addedNodes[k].className === "ember-view chat-line admin" || mutation.addedNodes[k].className === "ember-view chat-line")
{
isMessage = true;
mutation.addedNodes[k].onclick = function()
{
var message = this.getElementsByClassName("message")[0];
textArea.value = getRawMessage(message);
}
}
//shoutout to BetterTTV
else if(mutation.addedNodes[k].className === "chat-line admin" || mutation.addedNodes[k].className === "chat-line")
{
isMessage = true;
mutation.addedNodes[k].onclick = function()
{
var message = this.getElementsByClassName("message")[0];
textArea.value = decodeURIComponent(message.getAttribute('data-raw'));
}
}
else if(mutation.addedNodes[k].className === "ember-view chat-line action")
{
isMessage = true;
mutation.addedNodes[k].onclick = function()
{
var message = this.getElementsByClassName("message")[0];
textArea.value = "/me " + getRawMessage(message);
}
}
else if(mutation.addedNodes[k].className === "chat-line action")
{
isMessage = true;
mutation.addedNodes[k].onclick = function()
{
var message = this.getElementsByClassName("message")[0];
textArea.value = "/me " + decodeURIComponent(message.getAttribute('data-raw'));
}
}
if( isMessage === true && mutation.addedNodes[k].getElementsByClassName("message").textContent !== null)
{
mutation.addedNodes[k].onmouseover = function()
{
this.getElementsByClassName("message")[0].style.textDecoration = 'underline';
}
mutation.addedNodes[k].onmouseout = function()
{
this.getElementsByClassName("message")[0].style.textDecoration = 'none';
}
mutation.addedNodes[k].getElementsByClassName("message")[0].style.cursor = 'pointer';
}
}
});
});
var getRawMessage = function(message)
{
var rawMessage = "";
for(i = 0; i < message.childNodes.length; i++)
{
//emotes
if(message.childNodes[i].tagName == "IMG") rawMessage += message.childNodes[i].getAttribute('alt');
//links
else if(message.childNodes[i].tagName == 'A') rawMessage += message.childNodes[i].getAttribute('href');
//text
else rawMessage += message.childNodes[i].data;
}
return rawMessage;
}
chatObserver.observe(document.body, {childList: true, subtree: true});