Last active
October 5, 2016 01:20
-
-
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.
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, 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