tumblr.com Hide self-reblogs

Hide dash posts of people who reblog themselves

  1. // ==UserScript==
  2. // @name tumblr.com Hide self-reblogs
  3. // @description Hide dash posts of people who reblog themselves
  4. // @icon http://38.media.tumblr.com/avatar_fee7ff3e9d6a_48.png
  5. // @version 0.2.1
  6. // @license GNU General Public License v3
  7. // @copyright 2014, Nickel
  8. // @oujs:author Nickel
  9. // @grant none
  10. // @include *://www.tumblr.com/dashboard*
  11. // @namespace https://greasyfork.org/users/10797
  12. // ==/UserScript==
  13.  
  14. // TODO: add visible counter
  15. // TODO: also block reblogs from blogs you follow??
  16.  
  17. (function(){
  18.  
  19. var hidden = 0;
  20.  
  21. // don't run in frames
  22. if( frameElement ){ return; }
  23.  
  24. function work() {
  25. //console.log("hider working!");
  26. var i, j, child_post, child_reblog;
  27.  
  28. // iterate through all posts
  29. var elm = document.getElementsByClassName("post_info_fence");
  30. for (i=0; i<elm.length; i++) {
  31. if( elm[i].workedOn === true ) { continue; }
  32. elm[i].workedOn = true;
  33.  
  34. child_post = "";
  35. child_reblog = "";
  36.  
  37. // look for reblog child index, skip if not found
  38. for (j=0; j<elm[i].children.length; j++) {
  39. if( elm[i].children[j].classList.contains("reblog_source") ) {
  40. child_reblog = j;
  41. }
  42. }
  43. if ( ! child_reblog ) { continue; }
  44.  
  45. // look for post child index
  46. for (j=0; j<elm[i].children.length; j++) {
  47. if( elm[i].children[j].classList.contains("post_info_link") ) {
  48. child_post = j;
  49. }
  50. }
  51.  
  52. // compare tumblr-delivered attributes, if match is found, it's a self reblog
  53. // hide it.
  54. if ( elm[i].children[child_post].attributes[0].value ==
  55. elm[i].children[child_reblog].children[1].attributes[0].value ) {
  56. elm[i].parentNode.parentNode.parentNode.parentNode.parentNode.style.display = "none";
  57. hidden++;
  58. console.log("we've hidden " + hidden + " self-reblogs");
  59. }
  60. }
  61. }
  62.  
  63. // work whenever page changes
  64. var whatToObserve = {childList: true, attributes: true, subtree: true, attributeOldValue: true, attributeFilter: ['class', 'style']};
  65. var mutationObserver = new MutationObserver(function(mutations) {
  66. mutations.forEach(function(mutation) {
  67. if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
  68. work();
  69. }
  70. });
  71. });
  72. mutationObserver.observe(document.body, whatToObserve);
  73.  
  74. })();