/*
* @title quyo random autopagerize
* @description quyo random auopagerize
* @include http://quyo.hatelabo.jp/items/*
* @license MIT
*/
(function() {
var loading = false;
var x = new XMLHttpRequest();
var lastElement = function() {
var e = document.querySelectorAll('.container-mini.section');
return e[e.length - 1];
}();
var insertPoint = lastElement.nextSibling;
x.onload = function(e) {
if (x.status <= 200) {
var doc = e.target.response;
Array.prototype.forEach.call(doc.querySelectorAll('.container-mini.section'), function(elem) {
lastElement.parentElement.insertBefore(elem, insertPoint);
});
}
loading = false;
};
function loadNext() {
loading = true;
x.open('GET', '/items/next', true);
x.responseType = 'document';
x.send(null);
};
window.addEventListener('scroll', function() {
if (loading) return;
var remain = document.documentElement.scrollHeight - window.innerHeight - window.pageYOffset;
if (remain < 2000) {
loadNext();
}
}, false);
loadNext();
}());