@@ -1,7 +1,7 @@ /*- * @title quyo random autopagerize- * @description quyo random auopagerize- * @include http://quyo.hatelabo.jp/items/*+ * @title wikipedia random autopagerize + * @description wikipedia random auopagerize + * @include http://ja.wikipedia.org/wiki/* * @license MIT */ @@ -9,7 +9,7 @@ var loading = false; var x = new XMLHttpRequest(); var lastElement = function() {- var e = document.querySelectorAll('.container-mini.section');+ var e = document.querySelectorAll('div.mw-body'); return e[e.length - 1]; }(); var insertPoint = lastElement.nextSibling; @@ -17,7 +17,7 @@ x.onload = function(e) { if (x.status <= 200) { var doc = e.target.response;- Array.prototype.forEach.call(doc.querySelectorAll('.container-mini.section'), function(elem) {+ Array.prototype.forEach.call(doc.querySelectorAll('div.mw-body'), function(elem) { lastElement.parentElement.insertBefore(elem, insertPoint); }); } @@ -26,7 +26,7 @@ function loadNext() { loading = true;- x.open('GET', '/items/next', true);+ x.open('GET', '/wiki/%E7%89%B9%E5%88%A5:%E3%81%8A%E3%81%BE%E3%81%8B%E3%81%9B%E8%A1%A8%E7%A4%BA', true); x.responseType = 'document'; x.send(null); };
/*
* @title wikipedia random autopagerize
* @description wikipedia random auopagerize
* @include http://ja.wikipedia.org/wiki/*
* @license MIT
*/
(function() {
var loading = false;
var x = new XMLHttpRequest();
var lastElement = function() {
var e = document.querySelectorAll('div.mw-body');
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('div.mw-body'), function(elem) {
lastElement.parentElement.insertBefore(elem, insertPoint);
});
}
loading = false;
};
function loadNext() {
loading = true;
x.open('GET', '/wiki/%E7%89%B9%E5%88%A5:%E3%81%8A%E3%81%BE%E3%81%8B%E3%81%9B%E8%A1%A8%E7%A4%BA', 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();
}());