Adds a button to autoload all notes on Tumblr full page posts
当前为
// ==UserScript==
// @name Tumblr notes autoload
// @include http://*tumblr.com/post/*
// @description Adds a button to autoload all notes on Tumblr full page posts
// @version 1.1
// @author wOxxOm
// @contributor JesseW
// @namespace wOxxOm.scripts
// @license MIT License
// @run-at document-start
// @grant none
// ==/UserScript==
window.addEventListener('DOMContentLoaded', function(){
var btn;
var btnLabel = {load:'Load all notes', stop:'Stop loading notes', done:'All notes are loaded'};
function clickMore() {
if (btn.stopSignal) {
delete btn.stopSignal;
btn.textContent = btnLabel.load;
return;
}
var more = document.querySelector('.more_notes_link');
if (more) {
more.click();
var ob = new MutationObserver(function(mutations){
ob.disconnect();
setTimeout(function(){ clickMore() }, 200);
});
ob.observe(more.parentNode.parentNode, {subtree:true, childList:true});
}
else {
btn.textContent = btnLabel.done;
btn.disabled = true;
}
}
document.querySelector('.notes').insertAdjacentHTML('beforebegin',
'<button id="loadallBtn" style="margin-bottom:1em">' + btnLabel.load + '</button>');
btn = document.getElementById('loadallBtn');
btn.addEventListener('click', function(){
if (btn.textContent == btnLabel.load) {
btn.textContent = btnLabel.stop;
clickMore();
} else {
btn.stopSignal = true;
}
});
});