Advertisement
Guest User

DRACH_HIDER_V@

a guest
Aug 9th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name     DRACH_HIDER
  3. // @version  2
  4. // @match https://2ch.hk/*
  5. // @match http://2ch.hk/*
  6. // @require  https://code.jquery.com/jquery-3.3.1.slim.min.js
  7. // ==/UserScript==
  8.  
  9.  
  10. //!Posters you want to hide
  11. let ludiHoroshie = ['!!sW.cQVB3Lk'];
  12.  
  13. ////!Callback wrapper is required by MutationObserver to hide auto-updated threads/posts/replies/links to posts
  14. var callback = function() {
  15.  
  16.   //Hide the poster's posts
  17.   let tripPosters = document.getElementsByClassName('postertrip');
  18.  
  19.   for (let vsevishnii of tripPosters) {
  20.     if (ludiHoroshie.includes(vsevishnii.textContent) && vsevishnii.closest('.post-wrapper') !== null) {
  21.       vsevishnii.closest('.post-wrapper').style.display = 'none';
  22.     } else if (ludiHoroshie.includes(vsevishnii.textContent) && vsevishnii.closest('.oppost-wrapper') !== null) {
  23.       vsevishnii.closest('.thread').style.display = 'none';
  24.     }
  25.   }
  26.  
  27.   //Hide the poster's replies
  28.   ////Remember hidden poster's post ids and posts he/she replied to
  29.   let godnota = [];
  30.  
  31.   for (let vsevishnii of tripPosters) {
  32.     if (ludiHoroshie.includes(vsevishnii.textContent)) {
  33.       godnota.push($(vsevishnii).closest('.post.reply').data('num'));
  34.     }
  35.   }
  36.  
  37.   ////Find posts the poster replied to and hide his/her replies
  38.   let posters = document.getElementsByClassName('post-wrapper');
  39.  
  40.   for (let zabludshii of posters) {
  41.     for (let reply of $(zabludshii).find('.ABU-refmap').find('.post-reply-link')) {
  42.       if (godnota.includes($(reply).data('num'))) {
  43.         reply.style.display = 'none';
  44.       }
  45.     }
  46.   }
  47.  
  48.   //Hide replies to the poster's posts
  49.   for (let voproshayushii of posters) {
  50.     let molbi = $(voproshayushii).find('.post-message').children('.post-reply-link');
  51.     for (let molba of molbi) {
  52.       if (godnota.includes($(molba).data('num'))) {
  53.         $(molba).contents().unwrap();
  54.       }
  55.     }
  56.   }
  57. }
  58.  
  59. callback();
  60.  
  61. // Select the node that will be observed for mutations
  62. var targetNode = document.getElementById('posts-form');
  63.  
  64. // Options for the observer (which mutations to observe)
  65. var config = { attributes: false, childList: true, subtree: true };
  66.  
  67. // Create an observer instance linked to the callback function
  68. var observer = new MutationObserver(callback);
  69.  
  70. // Start observing the target node for configured mutations
  71. observer.observe(targetNode, config);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement