HugeFutaCocks

tumblr reblog remover script

Jan 16th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Tumblr Archive Reblog Remover
  3. // @author Arnold François Lecherche
  4. // @namespace greasyfork.org
  5. // @icon https://www.tumblr.com/favicon.ico
  6. // @version 0.1.2
  7. // @description Make browsing Tumblr archives easier.
  8. // @include http://*.tumblr.com/archive/*
  9. // @include https://*.tumblr.com/archive/*
  10. // @include http://*.tumblr.com/archive
  11. // @include https://*.tumblr.com/archive
  12. // @exclude http://www.tumblr.com/*
  13. // @exclude https://www.tumblr.com/*
  14. // @grant none
  15. // @run-at document-start
  16. // @copyright 2016 Arnold François Lecherche
  17. // ==/UserScript==
  18. /* jshint -W097 */
  19. ;(function setup(D, E, O, M, Date, undefined) {
  20. 'use strict';
  21. var remove = function (node) {
  22. if (typeof E.prototype.remove === 'function') remove = function remove(node) {return node.remove();};
  23. else remove = function remove(node) {return node.parentNode.removeChild(node);};
  24. return remove(node);
  25. }, swiftRemove = function swiftRemove() {
  26. var now = Date.now();
  27. if (now - check < 100) return;
  28. check = now;
  29. fake[0].addedNodes = archive.querySelectorAll('.not_mine.is_reblog');
  30. removeReblogs(fake);
  31. }, observerConfig = {
  32. attributes: false,
  33. characterData: false,
  34. childList: true,
  35. subtree: true
  36. }, hiddenKey = typeof Symbol !== 'undefined' ? Symbol('hidden') : '$hidden$' + M.random() + '$',
  37. observer = new MutationObserver(removeReblogs), d = {value: true}, check = Date.now(),
  38. fake = [{addedNodes:null}], archive, r;
  39. function clearChildren(node) {
  40. var nod;
  41. node.style.display = 'none';
  42. while ((nod = node.firstChild)) remove(nod);
  43. O.defineProperty(node, hiddenKey, d);
  44. }
  45. function removeReblogs(mutations) {
  46. observer.stop();
  47. var i = mutations.length, nodes, node, j, nc;
  48. while (i--) {
  49. nodes = mutations[i].addedNodes;
  50. j = nodes.length;
  51. while (j--) {
  52. node = nodes[j];
  53. if (node[hiddenKey]) continue;
  54. nc = node.classList;
  55. if (nc.contains('not_mine') && nc.contains('is_reblog')) clearChildren(node);
  56. }
  57. }
  58. observer.start();
  59. }
  60. function init() {
  61. D.removeEventListener('DOMContentLoaded', init, false);
  62. archive = D.querySelector('.l-content');
  63. observer.start();
  64. }
  65. observer.start = function () {
  66. observer.start = observer.observe.bind(observer, archive, observerConfig);
  67. observer.start();
  68. swiftRemove();
  69. };
  70. observer.stop = observer.disconnect.bind(observer);
  71. r = D.readyState;
  72. if (r === 'complete' || r === 'loaded' || r === 'interactive') init();
  73. else D.addEventListener('DOMContentLoaded', init, false);
  74. D.addEventListener('keydown', swiftRemove, true);
  75. D.addEventListener('scroll', swiftRemove, true);
  76. D.addEventListener('click', swiftRemove, true);
  77. })(document, Element, Object, Math, Date);
Add Comment
Please, Sign In to add comment