Guest User

Untitled

a guest
Apr 9th, 2022
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name     Cocoa Primer
  3. // @version  1
  4. // @grant    none
  5. // ==/UserScript==
  6.  
  7. const reg = /^https:\/\/boards\.4chan(nel)?\.org\/\w+\/thread\/\d+/;
  8.  
  9. if (reg.test(document.URL)) {
  10.     const cockoas = ["https://files.catbox.moe/mm50dl.png",
  11.                    "https://files.catbox.moe/bvuuat.png",
  12.                    "https://files.catbox.moe/xw9iob.png",
  13.                    "https://files.catbox.moe/rooom7.png",
  14.                    "https://files.catbox.moe/9pxahb.png",
  15.                    "https://files.catbox.moe/nliigw.png",
  16.                    "https://files.catbox.moe/mm50dl.png",
  17.                    "https://files.catbox.moe/n1qwor.png",
  18.                    "https://files.catbox.moe/cxawh2.png",
  19.                    "https://files.catbox.moe/r5h6dm.png"];
  20.   const chino = document.querySelector(".thread");
  21.   const byme = new MutationObserver(records => {
  22.     records.forEach(record => {
  23.       let newposts = [...record.addedNodes].filter(post => post.classList.contains("postContainer"));
  24.  
  25.       newposts.forEach(post => {
  26.         check_it(post);
  27.       });
  28.     });
  29.   });
  30.   const posts = chino.querySelectorAll(".postContainer");
  31.  
  32.   byme.observe(chino, { childList : true });
  33.  
  34.   posts.forEach(post => {
  35.     check_it(post);
  36.   });
  37.  
  38.   function check_it(post) {
  39.     const postNumber = Number(post.id.match(/\d+/)[0]);
  40.    
  41.     if (is_prime(postNumber)) {
  42.       console.log("checked");
  43.       add_cockoa(post);
  44.     }
  45.   }
  46.  
  47.   function is_prime(number) {
  48.     let sqrt = Math.sqrt(number);
  49.    
  50.     for (let i = 2; i <= sqrt; i++)
  51.         if (!(number % i)) {
  52.         return false;
  53.       }
  54.     return true;
  55.   }
  56.  
  57.   function add_cockoa(post) {
  58.     const img = new Image();
  59.    
  60.     img.src = cockoas[~~(Math.random() * cockoas.length)];
  61.     img.style.width = "40px";
  62.     img.addEventListener("load", () => {
  63.         const postInfo = post.querySelector(".postInfo");
  64.       const menuButton = post.querySelector(".menu-button");
  65.      
  66.       if (menuButton) {
  67.         menuButton.replaceWith(img);
  68.         postInfo.append(menuButton);
  69.       }
  70.       else
  71.         postInfo.append(img);
  72.     });
  73.   }
  74. }
Add Comment
Please, Sign In to add comment