Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Cocoa Primer
- // @version 1
- // @grant none
- // ==/UserScript==
- const reg = /^https:\/\/boards\.4chan(nel)?\.org\/\w+\/thread\/\d+/;
- if (reg.test(document.URL)) {
- const cockoas = ["https://files.catbox.moe/mm50dl.png",
- "https://files.catbox.moe/bvuuat.png",
- "https://files.catbox.moe/xw9iob.png",
- "https://files.catbox.moe/rooom7.png",
- "https://files.catbox.moe/9pxahb.png",
- "https://files.catbox.moe/nliigw.png",
- "https://files.catbox.moe/mm50dl.png",
- "https://files.catbox.moe/n1qwor.png",
- "https://files.catbox.moe/cxawh2.png",
- "https://files.catbox.moe/r5h6dm.png"];
- const chino = document.querySelector(".thread");
- const byme = new MutationObserver(records => {
- records.forEach(record => {
- let newposts = [...record.addedNodes].filter(post => post.classList.contains("postContainer"));
- newposts.forEach(post => {
- check_it(post);
- });
- });
- });
- const posts = chino.querySelectorAll(".postContainer");
- byme.observe(chino, { childList : true });
- posts.forEach(post => {
- check_it(post);
- });
- function check_it(post) {
- const postNumber = Number(post.id.match(/\d+/)[0]);
- if (is_prime(postNumber)) {
- console.log("checked");
- add_cockoa(post);
- }
- }
- function is_prime(number) {
- let sqrt = Math.sqrt(number);
- for (let i = 2; i <= sqrt; i++)
- if (!(number % i)) {
- return false;
- }
- return true;
- }
- function add_cockoa(post) {
- const img = new Image();
- img.src = cockoas[~~(Math.random() * cockoas.length)];
- img.style.width = "40px";
- img.addEventListener("load", () => {
- const postInfo = post.querySelector(".postInfo");
- const menuButton = post.querySelector(".menu-button");
- if (menuButton) {
- menuButton.replaceWith(img);
- postInfo.append(menuButton);
- }
- else
- postInfo.append(img);
- });
- }
- }
Add Comment
Please, Sign In to add comment