forked from jm2069872/textual-solarized-dark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
executable file
·90 lines (70 loc) · 2.4 KB
/
scripts.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
/* Defined in: "Textual 5.app -> Contents -> Resources -> JavaScript -> API -> core.js" */
var mappedSelectedUsers = new Array();
Textual.viewBodyDidLoad = function()
{
Textual.fadeOutLoadingScreen(1.00, 0.95);
setTimeout(function() {
Textual.scrollToBottomOfView()
}, 500);
}
// Textual.viewFinishedReload = function()
// {
// Textual.viewFinishedLoading();
// }
Textual.newMessagePostedToView = function(line)
{
var element = document.getElementById("line-" + line);
updateNicknameAssociatedWithNewMessage(element);
}
Textual.nicknameSingleClicked = function(e)
{
userNicknameSingleClickEvent(e);
}
function updateNicknameAssociatedWithNewMessage(e)
{
/* We only want to target plain text messages. */
var elementType = e.getAttribute("ltype");
if (elementType == "privmsg" || elementType == "action") {
/* Get the nickname information. */
var senderSelector = e.querySelector(".sender");
if (senderSelector) {
/* Is this a mapped user? */
var nickname = senderSelector.getAttribute("nickname");
/* If mapped, toggle status on for new message. */
if (mappedSelectedUsers.indexOf(nickname) > -1) {
toggleSelectionStatusForNicknameInsideElement(senderSelector);
}
}
}
}
function toggleSelectionStatusForNicknameInsideElement(e)
{
/* e is nested as the .sender so we have to go three parents
up in order to reach the parent div that owns it. */
var parentSelector = e.parentNode.parentNode.parentNode.parentNode;
parentSelector.classList.toggle("selectedUser");
}
function userNicknameSingleClickEvent(e)
{
/* This is called when the .sender is clicked. */
var nickname = e.getAttribute("nickname");
/* Toggle mapped status for nickname. */
var mappedIndex = mappedSelectedUsers.indexOf(nickname);
if (mappedIndex == -1) {
mappedSelectedUsers.push(nickname);
} else {
mappedSelectedUsers.splice(mappedIndex, 1);
}
/* Gather basic information. */
var documentBody = document.getElementById("body_home");
var allLines = documentBody.querySelectorAll('div[ltype="privmsg"], div[ltype="action"]');
/* Update all elements of the DOM matching conditions. */
for (var i = 0, len = allLines.length; i < len; i++) {
var sender = allLines[i].querySelectorAll(".sender");
if (sender.length > 0) {
if (sender[0].getAttribute("nickname") === nickname) {
toggleSelectionStatusForNicknameInsideElement(sender[0]);
}
}
}
}