Advertisement
Guest User

Untitled

a guest
Jun 25th, 2022
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        kys for 4chanX
  3. // @namespace   kys-4chanX
  4. // @match       https://boards.4channel.org/*/thread/*
  5. // @match       https://boards.4chan.org/*/thread/*
  6. // @grant       none
  7. // @run-at      document-start
  8. // @version     1.0
  9. // @author      -
  10. // @description 6/25/2022, 5:41:23 PM
  11. // ==/UserScript==
  12.  
  13. (function () {
  14.   const regex = [
  15.     /\bk+y+s+\b/gi,
  16.   ];
  17.  
  18.   document.addEventListener("4chanXInitFinished", function (e) {
  19.     const thread = document.querySelector(".thread"),
  20.       posts = thread.querySelectorAll(".postContainer");
  21.  
  22.     kys(posts); // init
  23.     document.addEventListener("ThreadUpdate", function (e) {
  24.       if (!e.detail[404]) {
  25.         if (e.detail.newPosts.length > 0) {
  26.           kys(e.detail.newPosts);
  27.         }
  28.       }
  29.     });
  30.  
  31.     function kys(list) {
  32.       let post, id;
  33.       for (const item of list) {
  34.         if (Array.isArray(list)) {
  35.           // new posts
  36.           id = item;
  37.           post = thread.querySelector(`.postContainer[id$="${id.split(".").pop()}"]`);
  38.         } else {
  39.           // thread init
  40.           post = item;
  41.           id = post.getAttribute("data-full-i-d");
  42.         }
  43.  
  44.         const comment = post.querySelector(".post.reply > blockquote");
  45.  
  46.         for (const rule of regex) {
  47.           if (comment && rule.test(comment.textContent)) {
  48.             // console.debug(id, comment);
  49.             comment.innerHTML = comment.innerHTML.replace(regex[0], "kiss your sister");
  50.  
  51.             break;
  52.           }
  53.         }
  54.       }
  55.     }
  56.   });
  57. })();
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement