Twitter.com Show More Tweets Auto-Loader

When you are trying to load lots of Tweets on Twitter you may end up pressing the "HOME"+"END" key combination repeatedly. This script is a workaround for this behaviour. To begin auto-loader double-click anywhere on the page. To disable auto-loader double-click anywhere on the page.

  1. // ==UserScript==
  2. // @name Twitter.com Show More Tweets Auto-Loader
  3. // @namespace https://github.com/their
  4. // @version 1.1
  5. // @include https://twitter.com/*
  6. // @author DS
  7. // @description When you are trying to load lots of Tweets on Twitter you may end up pressing the "HOME"+"END" key combination repeatedly. This script is a workaround for this behaviour. To begin auto-loader double-click anywhere on the page. To disable auto-loader double-click anywhere on the page.
  8. // @grant none
  9. // ==/UserScript==
  10. // Globals
  11. var t = {
  12. global_on_off: false,
  13. global_on_off_remover: false,
  14. which_scroll: 0,
  15. input_button_scroll: null,
  16. input_button_remover: null,
  17. input_remove_amount: null,
  18. div_scroll_extender: null,
  19. }
  20. add_elements();
  21. function add_elements() {
  22. // Scroll extender div to scrollIntoView
  23. var d = document.createElement('div');
  24. d.setAttribute('style', 'position:absolute;top:99999999999999999999px');
  25. document.body.appendChild(d);
  26. t.div_scroll_extender = d;
  27. // container
  28. var d = document.createElement('div');
  29. d.setAttribute('style', 'position:fixed;top:0;left:0;background-color:#eee;border:2px solid blue;z-index:9999999;');
  30. document.body.appendChild(d);
  31. // Auto-scroller on/off button
  32. var b = document.createElement('button');
  33. b.setAttribute('style', '');
  34. document.body.appendChild(b);
  35. b.onclick = toggle_scroll;
  36. b.innerText = 'Auto-Load Tweets (off)';
  37. t.input_button_scroll = b;
  38. d.appendChild(b);
  39. // Br
  40. var b = document.createElement('br');
  41. d.appendChild(b);
  42. // Show-Min toggle
  43. var b = document.createElement('button');
  44. b.setAttribute('style', '');
  45. d.appendChild(b);
  46. b.onclick = toggle_remover;
  47. b.innerText = 'Remove Tweets Under Threshold (off)';
  48. t.input_button_remover = b;
  49. // Br
  50. var b = document.createElement('br');
  51. d.appendChild(b);
  52. // Text
  53. d.appendChild(document.createTextNode('Remover Amount: '));
  54. // Show-Min amount
  55. var b = document.createElement('input');
  56. b.setAttribute('style', 'width:auto !important;text-align:center;padding:0;margin:0;');
  57. b.type = 'input';
  58. b.size = 4;
  59. d.appendChild(b);
  60. b.value = (localStorage['Twitter_Show_Min_Amount']) ? localStorage['Twitter_Show_Min_Amount'] : 10;
  61. b.addEventListener('keypress', function(e) {console.log(e);console.log(this.value);}, false);
  62. t.input_remove_amount = b;
  63. }
  64. function toggle_remover(e) {
  65. if (!t.global_on_off_remover) {
  66. t.global_on_off_remover = true;
  67. this.style.backgroundColor = 'LightGreen';
  68. this.innerText = 'Remove Tweets Under Threshold (on)';
  69. z();
  70. } else {
  71. t.global_on_off_remover = false;
  72. this.style.backgroundColor = '';
  73. this.innerText = 'Remove Tweets Under Threshold (off)';
  74. }
  75. }
  76. function toggle_scroll(e) {
  77. if (!t.global_on_off) {
  78. t.global_on_off = true;
  79. this.style.backgroundColor = 'LightGreen';
  80. this.innerText = 'Auto-Load Tweets (on)';
  81. scroll();
  82. } else {
  83. t.global_on_off = false;
  84. this.style.backgroundColor = '';
  85. this.innerText = 'Auto-Load Tweets (off)';
  86. }
  87. }
  88. function z() {
  89. if (!t.global_on_off_remover) return; // Quit
  90. var show_min = t.input_remove_amount.value;
  91. var x=document.getElementsByClassName('js-stream-item');
  92. for (var i=0;i<x.length;i++) {
  93. var nums = x[i].getElementsByClassName('ProfileTweet-actionCountForPresentation');
  94. var found = false;
  95. for (var j=0; j<nums.length; j++) {
  96. var n = nums[j].innerText.trim();
  97. //console.log(n*1);
  98. //if (n != '') // not blank
  99. if (n.indexOf('K') != -1) {
  100. n = n.replace('K', '').trim();
  101. n = n*1000;
  102. }
  103. if (n*1 >= show_min)
  104. found = true;
  105. }
  106. if (!found) {
  107. x[i].parentNode.removeChild(x[i]);
  108. return z(); // Start over.....
  109. }
  110. }
  111. // SetTimeout Here
  112. setTimeout(z, 400);
  113. }
  114. //z();
  115. // On dbl click
  116. //window.onkeypress = function(e) {
  117. // console.log(e.keyCode);return;
  118. window.ondblclick = function() {
  119. if (t.global_on_off) {
  120. t.global_on_off = false;
  121. }
  122. }
  123. // scroll
  124. function scroll() {
  125. if (!t.global_on_off) {
  126. return; // Quits
  127. }
  128. if (t.which_scroll === 0) {
  129. document.body.firstChild.scrollIntoView();
  130. } else {
  131. if (t.div_scroll_extender) {
  132. t.div_scroll_extender.scrollIntoView();
  133. }
  134. //var x = document.getElementsByClassName('spinner')[0];
  135. //if (x)
  136. // x.scrollIntoView(); // Not...Footer, -footer
  137. }
  138. t.which_scroll = (t.which_scroll === 0) ? 1 : 0;
  139. window.setTimeout(scroll, 600);
  140. }