add some documentation comments

This commit is contained in:
Valentin Boettcher 2020-04-09 16:46:59 +02:00
parent 9ce5352c6c
commit 0be4d433e9

View file

@ -9,20 +9,24 @@
} }
window.hasRun = true; window.hasRun = true;
/**
* Set up math delimiters.
*/
const math_config = [ const math_config = [
{left: "$$", right: "$$", display: true}, {left: "$$", right: "$$", display: true},
{left: "\\(", right: "\\)", display: false}, {left: "\\(", right: "\\)", display: false},
{left: "\\[", right: "\\]", display: true} {left: "\\[", right: "\\]", display: true}
] ]
/**
* Initialize Extension as soon as matrix has been loaded.
*/
function init() { function init() {
const header = document.querySelector('.mx_RoomList'); // render with KaTeX as soon as the message appears
let chat_observer = listen_on_chat_element();
function listen_on_chat_element() { function listen_on_chat_element() {
const chat_elem = document.querySelector('.mx_RoomView_MessageList'); const chat_elem = document.querySelector('.mx_RoomView_MessageList');
renderMathInElement(chat_elem, math_config); renderMathInElement(chat_elem, math_config);
const config = { attributes: true, childList: true, subtree: true };
const callback = function(mutationsList, observer) { const callback = function(mutationsList, observer) {
// Use traditional 'for loops' for IE 11 // Use traditional 'for loops' for IE 11
for(let mutation of mutationsList) { for(let mutation of mutationsList) {
@ -33,14 +37,13 @@
} }
} }
}; };
// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);
// Start observing the target node for configured mutations const observer = new MutationObserver(callback);
observer.observe(chat_elem, config); observer.observe(chat_elem, { attributes: true, childList: true, subtree: true });
return observer; return observer;
} }
// when changing the chat room, we have to create a new listener
function change_chat_element(mutationsList, observer) { function change_chat_element(mutationsList, observer) {
if (chat_observer) { if (chat_observer) {
chat_observer.disconnect(); chat_observer.disconnect();
@ -49,13 +52,16 @@
chat_observer = listen_on_chat_element(); chat_observer = listen_on_chat_element();
} }
// start listening
let chat_observer = listen_on_chat_element();
// start listening on the header as well
const header = document.querySelector('.mx_RoomList');
const header_obs = new MutationObserver(change_chat_element) const header_obs = new MutationObserver(change_chat_element)
const config = { attributes: true, childList: true, subtree: true }; header_obs.observe(header, { attributes: true, childList: true, subtree: true });
header_obs.observe(header, config);
} }
let = window.wrappedJSObject; // a clever hack to check if riot has been loaded yet
function wait_for_matrix() { function wait_for_matrix() {
if(!('matrixChat' in window.wrappedJSObject if(!('matrixChat' in window.wrappedJSObject
&& window.wrappedJSObject.matrixChat.firstSyncComplete)) && window.wrappedJSObject.matrixChat.firstSyncComplete))