Skip to content

Instantly share code, notes, and snippets.

@felberj
Last active December 11, 2015 09:42
Show Gist options
  • Save felberj/b5294ea899a341484d33 to your computer and use it in GitHub Desktop.
Save felberj/b5294ea899a341484d33 to your computer and use it in GitHub Desktop.
/* Defined in: "Textual.app -> Contents -> Resources -> JavaScript -> API -> core.js" */
var mappedSelectedUsers = new Array();
var Equinox = {
fadeNicks: true, // fade out nicknames when they appear multiple times in a row
fadeNicksFreq: 10, // how frequently to display a nick if they have fadeNickCounts lines in a row
showDateChanges: true, // show date changes
squashModes: true, // if a duplicate mode gets posted to the channel, squash it
squashTopics: true // if a duplicate topic gets posted to the channel, squash it
};
var mappedSelectedUsers = [];
var rs = { // room state
date: {
year: 0,
month: 0,
day: 0
},
mode: {
mode: undefined
},
nick: {
count: 1,
delete: false,
id: undefined,
nick: undefined
},
topic: {
delete: false,
topic: undefined
}
};
Textual.viewBodyDidLoad = function()
{
Textual.fadeOutLoadingScreen(1.00, 0.95);
setTimeout(function() {
Textual.scrollToBottomOfView()
}, 500);
}
Textual.newMessagePostedToView = function (line) {
'use strict';
var message = document.getElementById('line-' + line);
var clone, elem, getEmbeddedImages, i, mode, messageText, sender, topic;
// reset the message count and previous nick, when you rejoin a channel
if (message.getAttribute('ltype') !== 'privmsg') {
rs.nick.count = 1;
rs.nick.nick = undefined;
}
/* Let's kill topics that appear where they had already been set before
This happens when you join a room (like a reconnect) that you had been in and seen the topic before */
if (Equinox.squashTopics === true && message.getAttribute('ltype') === 'topic') {
topic = message.getElementsByClassName('message')[0].textContent.replace('Topic is ', '').replace(/\s+/, '');
if (message.getAttribute('command') === '332') { // an actual topic change
// hide the topic if it's the same topic again
if (topic === rs.topic.topic) {
message.className = message.className + " deleted";
rs.topic.delete = true;
}
rs.topic.topic = topic;
}
if ((message.getAttribute('command') === '333') && (rs.topic.delete === true)) {
message.className = message.className + " deleted";
rs.topic.delete = false;
}
}
// much like we suppress duplicate topics, we want to suppress duplicate modes
if (Equinox.squashModes === true && message.getAttribute('ltype') === 'mode') {
mode = message.getElementsByClassName('message')[0].textContent.replace(/\s+/, '');
if (mode === rs.mode.mode) {
message.className = message.className + " deleted";
} else {
rs.mode.mode = mode;
}
}
// hide messages about yourself joining
if ((message.getAttribute('ltype') === 'join') || (message.getAttribute('ltype') === 'part')) {
if (message.getElementsByClassName('message')[0].getElementsByTagName('b')[0].textContent === app.localUserNickname()) {
message.className = message.className + " deleted";
}
}
/* clear out all the old disconnect messages, if you're currently connected to the channel
note that normally Textual.handleEvent will catch this, but if you reload a theme, they will reappear */
if ((message.getAttribute('ltype') === 'debug') && (message.getAttribute('command') === '-100')) {
if (app.channelIsJoined() &&
(message.getElementsByClassName('message')[0].textContent.search('Disconnect') !== -1)) {
message.className = message.className + " deleted";
}
} else {
// call the dateChange() function, for any message with a timestamp that's not a debug message
if (message.getAttribute('timestamp')) {
//dateChange(message);
}
}
if (message.getAttribute('encrypted') === 'true') {
messageText = message.querySelector('.innerMessage');
if (messageText.innerText.indexOf('+OK') !== -1) {
message.setAttribute('encrypted', 'failed');
}
}
getEmbeddedImages = message.querySelectorAll('img');
if (getEmbeddedImages) {
for (i = 0; i < getEmbeddedImages.length; i++) {
getEmbeddedImages[i].onload = function (e) {
setTimeout(function () {
if (e.target.offsetHeight > (window.innerHeight - 150)) {
e.target.style.height = (window.innerHeight - 150);
}
}, 1000);
};
}
}
updateNicknameAssociatedWithNewMessage(message);
};
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]);
}
}
}
}
@felberj
Copy link
Author

felberj commented Dec 11, 2015

I do not remove messages anymore. You know have to add

.deleted {
    display: none;
}

to your style to hide removed messages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment