Created
October 5, 2016 00:58
-
-
Save panzi/4f45cd759ff08e85f494b2b61814506e to your computer and use it in GitHub Desktop.
Automaticall scroll the chat on rabb.it to the bottom. You need to install the Greasemonkey Browser add-on.
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 Auto-scroll in rabb.it chat | |
// @namespace http://panzi.github.io/ | |
// @description Automaticall scroll the chat on rabb.it to the bottom. | |
// @include https://www.rabb.it/* | |
// @include http://www.rabb.it/* | |
// @include https://rabb.it/* | |
// @include http://rabb.it/* | |
// @version 1.0 | |
// ==/UserScript== | |
"use strict"; | |
var autoScrollObservers = []; | |
function installAutoScroll () { | |
uninstallAutoScroll(); | |
var scrollAreas = document.querySelectorAll(".conversationMessageCollectionView"); | |
Array.prototype.forEach.call(scrollAreas, scrollArea => { | |
var observer = new MutationObserver(() => { | |
// delay this after the mutation so that we get the updated values | |
setTimeout(scrollToBottom, 0); | |
setTimeout(scrollToBottom, 300); | |
}); | |
observer.observe(scrollArea, {childList: true}); | |
autoScrollObservers.push(observer); | |
function scrollToBottom () { | |
if (scrollArea.scrollHeight > scrollArea.offsetHeight && | |
scrollArea.scrollHeight <= (scrollArea.offsetHeight + scrollArea.scrollTop + 300)) { | |
scrollArea.scrollTop = scrollArea.scrollHeight - scrollArea.offsetHeight; | |
} | |
} | |
}); | |
} | |
function uninstallAutoScroll () { | |
autoScrollObservers.forEach(observer => observer.disconnect()); | |
autoScrollObservers = []; | |
} | |
installAutoScroll(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment