Last active
November 24, 2017 22:51
-
-
Save wsoyka/405c1d99b860da990c403a197aa1bd75 to your computer and use it in GitHub Desktop.
Aurora Smalltalk Timestamper Userscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Aurora Smalltalk Timestamper & Co | |
// @namespace https://gist.githubusercontent.com/wsoyka/405c1d99b860da990c403a197aa1bd75/raw/13fbc2896a98410af054d73e8ea8299b5b84bfa0/aurora_timestamper.js | |
// @version 0.4 | |
// @description temporary solution to showing timestamps in aurora and other small fixes | |
// @author Wolfram Soyka | |
// @match http*://*.aurora.iguw.tuwien.ac.at/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var displayTimestamps = function (){ | |
//Get css path. Aurora already uses jQuery. | |
//https://stackoverflow.com/a/5708130/3665531 | |
jQuery.fn.extend({ | |
getPath: function () { | |
var allSiblings; | |
var path, node = this; | |
while (node.length) { | |
var realNode = node[0], name = realNode.localName; | |
if (!name) break; | |
name = name.toLowerCase(); | |
var parent = node.parent(); | |
var sameTagSiblings = parent.children(name); | |
if (sameTagSiblings.length > 1) { | |
allSiblings = parent.children(); | |
var index = allSiblings.index(realNode) + 1; | |
if (index > 1) {name += ':nth-child(' + index + ')';} | |
} | |
path = name + (path ? '>' + path : ''); | |
node = parent; | |
} | |
return path; | |
} | |
}); | |
//get time in HH:mm:ss | |
function getFormattedTime(){ | |
return new Date().toTimeString().split(" ")[0]; | |
} | |
//Based on: https://developers.google.com/web/updates/2012/02/Detect-DOM-changes-with-Mutation-Observers | |
//watch Element for new Messages | |
var observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
for (var i = 0; i < mutation.addedNodes.length; i++){ | |
var origEl = $(mutation.addedNodes[i]); | |
var path = origEl.getPath(); | |
var el = $(path+">.ChatMessageBody>p"); | |
if(el.length<1) return; | |
var txt = el.text(); | |
el.html(txt+" <span style='font-size:10px'>"+getFormattedTime()+"</span>"); | |
//play beep only if message not from me | |
if(!origEl.hasClass("self_author")) $('#myBeep')[0].play(); | |
//scroll down - this WILL scroll down whenever a new message is added | |
$('#small_talk').scrollTop($('#small_talk')[0].scrollHeight); | |
} | |
}); | |
}); | |
//watch Chat for new messages | |
observer.observe(document.querySelector('.MessageList'), { childList: true }); | |
}; | |
//to not show timestamps for old messages (would show page load time - not helpful) wait 1 second. all new messages will show timestamp | |
setTimeout(function(){displayTimestamps();}, 1000); | |
//notification beep für messages | |
$('body').append('<audio id="myBeep" src="https://freesound.org/data/previews/263/263133_2064400-lq.mp3" autostart="false" ></audio>'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment