Tumblr notes autoload

Adds a button to autoload all notes on Tumblr full page posts

  1. // ==UserScript==
  2. // @name Tumblr notes autoload
  3. // @include http://*tumblr.com/post/*
  4. // @description Adds a button to autoload all notes on Tumblr full page posts
  5. // @version 1.2.1
  6. // @author wOxxOm
  7. // @contributor JesseW
  8. // @namespace wOxxOm.scripts
  9. // @license MIT License
  10. // @run-at document-start
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. var maxLoadOnStart = 100; // load no more than 100 notes when the page is displayed
  15.  
  16. window.addEventListener('DOMContentLoaded', function(){
  17. var btn;
  18. var btnLabel = {load:'Load all notes', stop:'Stop loading notes', done:'All notes are loaded'};
  19. var totalNotes;
  20.  
  21. function clickMore() {
  22. var loadedNotes = document.querySelectorAll('ol.notes > .note').length;
  23. if (btn.autoSignal && loadedNotes >= maxLoadOnStart) {
  24. delete btn.autoSignal;
  25. btn.stopSignal = true;
  26. }
  27. var more = document.querySelector('.more_notes_link');
  28. if (more) {
  29. var notesToLoad = totalNotes ? ' (' + Math.max(1, totalNotes - loadedNotes) + ' more)' : '';
  30. if (btn.stopSignal) {
  31. delete btn.stopSignal;
  32. btn.textContent = btnLabel.load + notesToLoad;
  33. return;
  34. }
  35. btn.textContent = btnLabel.stop + notesToLoad;
  36. more.click();
  37. var ob = new MutationObserver(function(mutations){
  38. ob.disconnect();
  39. setTimeout(function(){ clickMore() }, 200);
  40. });
  41. ob.observe(more.parentNode.parentNode, {subtree:true, childList:true});
  42. }
  43. else {
  44. btn.textContent = btnLabel.done;
  45. btn.disabled = true;
  46. }
  47. }
  48. document.querySelector('ol.notes').insertAdjacentHTML('beforebegin',
  49. '<button id="loadallBtn" style="margin-bottom:1em">' + btnLabel.load + '</button>');
  50. btn = document.getElementById('loadallBtn');
  51. btn.addEventListener('click', function(){
  52. if (!btn.textContent.match(btnLabel.stop)) {
  53. btn.textContent = btnLabel.stop;
  54. clickMore();
  55. } else {
  56. btn.stopSignal = true;
  57. }
  58. });
  59. Array.prototype.some.call(document.querySelectorAll('.info, a[href*="/post/"], .permainfo'), function(n){
  60. var m = n.textContent.match(/([\d,]+) notes/);
  61. if (m) {
  62. totalNotes = parseInt(m[1].replace(',',''));
  63. return true;
  64. }
  65. });
  66.  
  67. btn.autoSignal = true;
  68. btn.click();
  69. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址