Advertisement
Guest User

JS to Block Memeflaggot OPs from /pol/ v3.0

a guest
Jun 26th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name Block Memeflaggot OPs on /pol/
  3. // @namespace 4chan
  4. // @match https://boards.4chan.org/pol/catalog
  5. // @grant none
  6. // ==/UserScript==
  7.  
  8. const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
  9. // const sticky_posts = ["124205675", "143684145"];
  10. // const memeflaggots = ["Anarcho-Capitalist", "Anarchist", "Black Nationalist", "Confederate", "Communist", "Catalonia", "Democrat", "European", "Fascist", "Gadsden", "Gay", "Jihadi", "Kekistani", "Muslim", "National Bolshevik", "Nazi", "Hippie", "Pirate", "Republican", "Templar", "Tree Hugger", "United Nations", "White Supremacist", "LGBT", "Black Lives Matter", "Commie", "DEUS VULT"];
  11.  
  12. let running_mutex = false;
  13. let break_requested = false;
  14. const delete_memeflaggot_threads = async() => {
  15.   if(running_mutex) {
  16.     break_requested = true;
  17.     while(running_mutex)
  18.       await sleep(100);
  19.   }
  20.   running_mutex = true;
  21.   let thread_nodes = [...document.querySelectorAll("div.thread")];
  22.  
  23.   while(thread_nodes.length != 201) {
  24.     await sleep(500);
  25.     thread_nodes = [...document.querySelectorAll("div.thread")];
  26.   }
  27.  
  28.   let tt = document.createElement("tt");
  29.   document.body.appendChild(tt);
  30.   tt.outerHTML = `<div style="position: fixed; top: 50px; right: 50px; display: block;" id="mm-tooltip">
  31.                       <div class="tooltip-inner" style="transition: opacity .1s ease; opacity: .95; max-width: 200px; white-space: pre-wrap!important; overflow: hidden; text-overflow: ellipsis; padding: 6px 11px; border-radius: 4px; color: #fff; text-align: center; text-decoration: none; background-color: #14171a">Purging cancer...</div>
  32.                   </div>`;
  33.   tt = document.querySelector("div#mm-tooltip");
  34.   thread_nodes.splice(0, 2);
  35.   let counter = 0;
  36.  
  37.   for(let i = 0; i < thread_nodes.length; i++) {
  38.     if(break_requested) {
  39.       break_requested = false;
  40.       break;
  41.     }
  42.     let thread_id = thread_nodes[i].id.replace("thread-", "");
  43.     let res = await fetch(`https://a.4cdn.org/pol/thread/${thread_id}.json`, {"credentials":"omit","referrer":"https://boards.4chan.org/","referrerPolicy":"origin","body":null,"method":"GET","mode":"cors"});
  44.     let obj = await res.json();
  45.     if(obj.posts[0].hasOwnProperty("troll_country")) {
  46.       try {
  47.         thread_nodes[i].parentElement.removeChild(thread_nodes[i]);
  48.       }
  49.       catch(ex) {
  50.         //do nothing
  51.       }
  52.       counter++;
  53.     }
  54.     tt.children[0].innerText = `Purging cancer...(${i}/202)`;
  55.   }
  56.  
  57.   tt.parentElement.removeChild(tt);
  58.  
  59.   console.log(`Memeflaggots thread clean count: ${counter}`);
  60.   running_mutex = false;
  61. };
  62.  
  63. delete_memeflaggot_threads();
  64.  
  65. document.querySelector("select#order-ctrl").onchange = delete_memeflaggot_threads;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement