Skip to content

Instantly share code, notes, and snippets.

@panzi
Last active October 5, 2016 01:20
Show Gist options
  • Save panzi/069883422989723de0b137befa2997c1 to your computer and use it in GitHub Desktop.
Save panzi/069883422989723de0b137befa2997c1 to your computer and use it in GitHub Desktop.
This stops auto-play of videos (vines, GIFs) on TweetDeck. You can still manually play videos by clicking them, though.
// ==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, subtree: true, characterData: true});
autoScrollObservers.push(observer);
function scrollToBottom () {
if (scrollArea.scrollHeight > scrollArea.offsetHeight &&
scrollArea.scrollHeight <= (scrollArea.offsetHeight + scrollArea.scrollTop + 300)) {
scrollArea.scrollTop = scrollArea.scrollHeight - scrollArea.offsetHeight;
}
else {
console.log('no auto scroll', 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