Advertisement
runewalsh

Моя версия~

Aug 8th, 2018
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name     DRACH_HIDER
  3. // @version  1.Rika1
  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. //!Posters you want to hide
  10. let ludiHoroshie = ['!!sW.cQVB3Lk'];
  11.  
  12. // Hide the poster's posts and remember their ids
  13. let posters = document.getElementsByClassName('post-wrapper');
  14. let tripPosters = document.getElementsByClassName('postertrip');
  15. let godnota = [];
  16.  
  17. for (let vsevishnii of tripPosters) {
  18.   if (ludiHoroshie.includes(vsevishnii.textContent)) {
  19.     godnota.push($(vsevishnii).closest('.post.reply').data('num'));
  20.  
  21.     let post = vsevishnii.closest('.post-wrapper');
  22.     if (post !== null) {
  23.       post.style.display = 'none';
  24.     }
  25.    
  26.     if (vsevishnii.closest('.oppost-wrapper') !== null) {
  27.       vsevishnii.closest('.thread').style.display = 'none';
  28.     }
  29.   }
  30. }
  31.  
  32. // Hide links to the poster's posts inside other posts bodies
  33. for (let voproshayushii of posters) {
  34.   let molbi = $(voproshayushii).find('.post-message').children('.post-reply-link');
  35.   for (let molba of molbi) {
  36.     if (godnota.includes($(molba).data('num'))) {
  37.       $(molba).hide();
  38.     }
  39.   }
  40. }
  41.  
  42. // !Copypasted sleep function (Required because for some reason replies don't load before this script is executed)
  43. function sleep(ms) {
  44.   return new Promise(resolve => setTimeout(resolve, ms));
  45. }
  46.  
  47. // Find posts the poster replied to and hide links to his/her replies in "Ответы:" section
  48. (async function() {
  49.   console.log('Taking a break...');
  50.   await sleep(2000);
  51.   console.log('Two second later');
  52.  
  53.   for (let zabludshii of posters) {
  54.     let refmap = $(zabludshii).find('.ABU-refmap');
  55.     let links_total = 0, links_hidden = 0;
  56.  
  57.     for (let reply of refmap.find('.post-reply-link')) {
  58.       links_total += 1;
  59.  
  60.       if (godnota.includes($(reply).data('num'))) {
  61.         reply.style.display = 'none';
  62.         links_hidden += 1;
  63.       }
  64.     }
  65.  
  66.     // hide the whole "Ответы:" section if it became empty
  67.     if (links_hidden == links_total) {
  68.       refmap.hide();
  69.     }
  70.   }
  71. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement