Advertisement
Guest User

Purple Texting

a guest
Jul 18th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name YenTxt 4Chan
  3. // @namespace RedTxtMaker
  4. // @version 2020.07.18
  5. // @match *://boards.4chan.org/*
  6. // @match *://boards.4channel.org/*
  7. // @match *://nineball.party/*
  8. // @match *://grimchan.xyz/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. function makePurple(root){
  13.     if(root.nodeType !== Node.ELEMENT_NODE){
  14.         return;
  15.     }
  16.  
  17.     var halfchan = Array.from(root.getElementsByClassName('postMessage'));
  18.     if(root.classList.contains('postmessage')){
  19.         halfchan.unshift(root);
  20.     }
  21.     var nineball = Array.from(root.getElementsByTagName('BLOCKQUOTE'));
  22.     var grimchan = Array.from(root.getElementsByClassName('body'));
  23.  
  24.     var nodes = halfchan.concat(nineball).concat(grimchan)
  25.  
  26.     nodes.forEach(function(node){
  27.         if(node.textContent.indexOf('¥') <= -1){
  28.             return;
  29.         }
  30.         var txtItterator = document.createNodeIterator(node, NodeFilter.SHOW_TEXT);
  31.         var txtNode;
  32.         while((txtNode = txtItterator.nextNode())){
  33.             var hashIndex = txtNode.textContent.indexOf('¥');
  34.             if(hashIndex > -1){
  35.                 var splitNode = txtNode.splitText(hashIndex);
  36.  
  37.                 var span = document.createElement('span');
  38.                 span.style.color = "#9370DB";
  39.                 span.className = "the_m_Word";
  40.  
  41.                 span.appendChild(splitNode);
  42.                 txtNode.parentNode.insertBefore(span, txtNode.nextSibling);
  43.  
  44.                 txtItterator.nextNode();
  45.             }
  46.         }
  47.     });
  48. }
  49.  
  50. makePurple(document.body);
  51.  
  52. new MutationObserver(function(mutations){
  53.     mutations.forEach(function(mutation){
  54.         mutation.addedNodes.forEach(makePurple);
  55.     });
  56. }).observe(document.body, {childList: true, subtree: true});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement