-
-
Save Constellation/105046 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 twitter.AutoPager | |
// @namespace http://ss-o.net/ | |
// @version 0.1 | |
// @include http://twitter.com/* | |
// @include https://twitter.com/* | |
// ==/UserScript== | |
(function autopager(unsafeWindow,loaded){ | |
if (!loaded && window.opera && document.readyState == 'interactive') { | |
document.addEventListener('DOMContentLoaded', function(){autopager(unsafeWindow,true);}, false); | |
return; | |
} | |
var state = true; | |
var remainHeight = 400; | |
var loading = false; | |
var filter = function(){ | |
loading = false; | |
}; | |
if (typeof unsafeWindow.onPageChange === 'function') { | |
var _onPageChange = unsafeWindow.onPageChange; | |
unsafeWindow.onPageChange = function(){ | |
_onPageChange(); | |
filter(); | |
}; | |
} else { | |
unsafeWindow.onPageChange = filter; | |
} | |
window.addEventListener('scroll', function(){ | |
if (loading) return; | |
var remain = document.documentElement.scrollHeight - window.innerHeight - window.pageYOffset; | |
if (state && remain < remainHeight) | |
click_more(); | |
}, false); | |
function click_more(){ | |
var event = document.createEvent('MouseEvents'); | |
event.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); | |
get_more().dispatchEvent(event); | |
loading = true; | |
} | |
function get_more(){ | |
return document.getElementById('more'); | |
} | |
})(this.contentWindow||this.unsafeWindow||window,0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment