daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        medukatheguca
  3. // @namespace   megucasoft
  4. // @description roll highlighter
  5. // @include     https://meguca.org/*
  6. // @version     0.7.6
  7. // @grant       none
  8. // ==/UserScript==
  9.  
  10. function insertCuteIntoCSS() {
  11.     var css = document.createElement("style");
  12.     css.type = "text/css";
  13.     css.innerHTML = ".super_roll { animation: pink_blinker 0.4s linear 100; color: pink; } @keyframes pink_blinker { 50% { color: deeppink } }" +
  14.         ".lewd_roll { animation: lewd_blinker 0.7s linear 57; color: pink; } @keyframes lewd_blinker { 50% { color: #FFD6E1 } }" +
  15.         ".kuso_roll { animation: brown_blinker 1s linear 40; color: #825025; } @keyframes brown_blinker { 50% { opacity: 0.7 } }" +
  16.         ".dubs_roll { animation: blue_blinker 0.4s linear 100; color: aqua; } @keyframes blue_blinker { 50% { color: blue } }" +
  17.         ".trips_roll { animation: yellow_blinker 0.4s linear 100; color: yellow; } @keyframes yellow_blinker { 50% { color: darkorange } }" +
  18.         ".quads_roll { animation: green_blinker 0.4s linear 100; color: lime; } @keyframes green_blinker { 50% { color: darkgreen } }" +
  19.         ".rainbow_roll { animation: rainbow_blinker 2s linear infinite; color: red; } @keyframes rainbow_blinker { 14% {color: orange} 28% {color: yellow} 42% {color: green} 57% {color: blue} 71% {color: indigo} 85% {color: violet} }" +
  20.         ".dangerous_roll {font-size: 110%; color: #f00000; }" +
  21.         ".dead_fuck { color: #e55e5e; }" +
  22.         ".thousand_pyu { animation: pyu_blinker 0.4s linear 100; color: aqua; } @keyframes pyu_blinker { 50% { color: white } }";
  23.     document.head.appendChild(css);
  24. }
  25.  
  26. function readPostsForRolls() {
  27.     var posts = document.getElementsByClassName('post-container');
  28.     for (var i = 0; i < posts.length; i++) {
  29.         var post = posts[i];
  30.         handlePost(post);
  31.     }
  32. }
  33.  
  34. function parseRoll(post, die) {
  35.     var n = die[1];
  36.     var m = die[2];
  37.     var x = die[3];
  38.     var divided = (""+x).split(""); //Splits the number into single digits to check for dubs, trips, etc
  39.     if (n == "") {
  40.         n = 1;
  41.     }
  42.  
  43.     var maxRoll = n * m; // because javascript just lets you multiply strings together...
  44.     var before = post.innerHTML.substring(0, die.index);
  45.     var after = post.innerHTML.substring(die.index + die[0].length);
  46.  
  47.     // do nothing for totals below 10, or for n d1s
  48.     if (maxRoll < 10 || m == 1) {
  49.         return;
  50.     }
  51.  
  52.     if (n == 1 && m == x && x == 7777) { // Marrying navy-tan!
  53.         var rollHTML = "<strong class=\"rainbow_roll\"> Congrats! You get to marry navy-tan! " + die[0].substring(8);
  54.         post.innerHTML = before + rollHTML + after;
  55.     } else if (maxRoll == x) {
  56.         var rollHTML = "<strong class=\"super_roll\"> " + die[0].substring(8);
  57.         post.innerHTML = before + rollHTML + after;
  58.     } else if (x == 1) {
  59.         var rollHTML = "<strong class=\"kuso_roll\"> " + die[0].substring(8);
  60.         post.innerHTML = before + rollHTML + after;
  61.     } else if (x == 69 || x == 6969) {
  62.         var rollHTML = "<strong class=\"lewd_roll\"> " + die[0].substring(8);
  63.         post.innerHTML = before + rollHTML + after;
  64.     } else if (checkEm(divided)) {
  65.         switch (divided.length) {
  66.             case 2:
  67.                 var rollHTML = "<strong class=\"dubs_roll\"> " + die[0].substring(8);
  68.                 break;
  69.             case 3:
  70.                 var rollHTML = "<strong class=\"trips_roll\"> " + die[0].substring(8);
  71.                 break;
  72.             case 4:
  73.                 var rollHTML = "<strong class=\"quads_roll\"> " + die[0].substring(8);
  74.                 break;
  75.             default: // QUINTS!!!
  76.                 var rollHTML = "<strong class=\"rainbow_roll\"> " + die[0].substring(8);
  77.                 break;
  78.         }
  79.         post.innerHTML = before + rollHTML + after;
  80.     }
  81. }
  82.  
  83. function parseRoulette(post, die) {
  84.     var postEnding = post.innerHTML.substring(post.innerHTML.length-2);
  85.     var before = post.innerHTML.substring(0, die.index);
  86.     var after = post.innerHTML.substring(die.index + 18);
  87.  
  88.     if (die[1] == 1)
  89.         post.innerHTML = before + "<strong class=\"dead_fuck\"> #roulette " + after;
  90.     else
  91.         post.innerHTML = before + "<strong> #roulette " + after;
  92.  
  93.     // if post ends in "g>" then the strong tag is already set
  94.     if(die[1] == 1 && postEnding != "g>")
  95.         post.innerHTML += "\n <strong class=\"dangerous_roll\"> USER WAS KILLED FOR THIS ROLL</strong>";
  96. }
  97.  
  98. function parsePyu(post, pyu) {
  99.     var n = pyu[1];
  100.     var nsub;
  101.     var before = post.innerHTML.substring(0, pyu.index);
  102.     var after = post.innerHTML.substring(pyu.index + pyu[0].length);
  103.    
  104.     if (n % 1000 == 0) {
  105.         var pyuHTML = "<strong class=\"thousand_pyu\"> 💦 " + pyu[0].substring(8) + " 💦 ";
  106.         post.innerHTML = before + pyuHTML + after;
  107.     }
  108. }
  109.  
  110. function parseDecide(post, decide) {
  111.     var options = decide[1].split(",");
  112.     var n = decide[2];
  113.     var m = decide[3];
  114.    
  115.     var before = post.innerHTML.substring(0, decide.index);
  116.     var after = post.innerHTML.substring(decide.index + decide[0].length);
  117.    
  118.     if (options.length != n) return;
  119.     options[m-1] = "<strong class=\"dubs_roll\">" + options[m-1] + "</strong>";
  120.     var newInner = options.toString();
  121.     var retreivedRoll = " <strong>#d" + n + " (" + m + ")</strong>";
  122.     post.innerHTML = before + newInner + retreivedRoll + after;
  123. }
  124.  
  125. function checkEm(divided) {
  126.     if (divided.length < 2) return false;
  127.  
  128.     var repeatingdigits=true;
  129.     for (var u=divided.length-2; u>=0; u-=1) {
  130.         if (divided[u]!=divided[divided.length-1]) {
  131.             repeatingdigits=false;
  132.             break;
  133.         }
  134.     }
  135.  
  136.     return repeatingdigits;
  137. }
  138.  
  139. function findMultipleShitFromAString(s, re) {
  140.     var result = [];
  141.     var m;
  142.     while (true) {
  143.         m = re.exec(s);
  144.         if (m) result.push(m);
  145.         else break;
  146.     }
  147.     return result;
  148. }
  149.  
  150. function handlePost(post) {
  151.     var dice = findMultipleShitFromAString(post.innerHTML, /<strong>#(\d*)d(\d+) \((?:[\d +]* )*=? ?(\d+)\)<\/strong>/g);
  152.     for (var j = dice.length - 1; j >= 0; j--) {
  153.         parseRoll(post, dice[j]);
  154.     }
  155.     var pyu = findMultipleShitFromAString(post.innerHTML, /<strong>#pyu \(([\d+]*)\)<\/strong>/g);
  156.     for (var j = pyu.length - 1; j >= 0; j--) {
  157.         parsePyu(post, pyu[j]);
  158.     }
  159.     var rouletteDice = findMultipleShitFromAString(post.innerHTML, /#roulette <strong>#d6 \((?:[\d +]* )*=? ?(\d+)\)<\/strong>/g);
  160.     for (var j = rouletteDice.length - 1; j >= 0; j--) {
  161.         parseRoulette(post, rouletteDice[j]);
  162.     }
  163.     var decide = findMultipleShitFromAString(post.innerHTML, /\[([^\]]*)\] <strong>#d([0-9]+) \(([0-9]+)\)<\/strong>/g);
  164.     for (var j = decide.length - 1; j >= 0; j--) {
  165.         parseDecide(post, decide[j]);
  166.     }
  167. }
  168.  
  169. function setObservers() {
  170.     var thread = document.getElementById("thread-container");
  171.  
  172.     var observer = new MutationObserver(function(mutations) {
  173.         mutations.forEach(function(mutation) {
  174.             if (mutation.addedNodes.length == 0) return;
  175.             var post = mutation.addedNodes[0].getElementsByClassName("post-container")[0];
  176.  
  177.             var observer2 = new MutationObserver(function(mutations2) {
  178.                 mutations2.forEach(function(mutation2) {
  179.                     if (mutation2.addedNodes.length > 0) {
  180.                         handlePost(post);
  181.                     }
  182.                 });
  183.             });
  184.  
  185.             // configuration of the observer:
  186.             var config = { attributes: true, childList: true, characterData: true };
  187.  
  188.             // pass in the target node, as well as the observer options
  189.             observer2.observe(post.children[0], config);
  190.         });
  191.     });
  192.  
  193.     // configuration of the observer:
  194.     var config = { attributes: true, childList: true, characterData: true };
  195.  
  196.     // pass in the target node, as well as the observer options
  197.     observer.observe(thread, config);
  198. }
  199.  
  200. function hackLatsOptions() {
  201.     var options = document.getElementById("options");
  202.     var tab_butts = options.getElementsByClassName("tab-butts")[0];
  203.     var tab_cont = options.getElementsByClassName("tab-cont")[0];
  204.  
  205.     var new_butt /*lewd*/ = "<a class=\"tab-link\" data-id=\"5\">Meguca Userscript</a>";
  206.     var new_cont = "<div data-id=\"5\"><input type=\"checkbox\" name=\"eden\" id=\"eden\"> <label for=\"eden\">Eden Now Playing Banner (not working)</label><br> <input type=\"checkbox\" name=\"diceColoring\" id=\"diceColoring\"> <label for=\"diceColoring\">Dice coloring</label><br> <input type=\"checkbox\" name=\"roulette\" id=\"roulette\"> <label for=\"roulette\">Roulette</label><br> <p>Use <strong>#roulette #d6</strong> to roll the roulette</p></div>";
  207.  
  208.     tab_butts.innerHTML += new_butt;
  209.     tab_cont.innerHTML += new_cont;
  210. }
  211.  
  212. insertCuteIntoCSS();
  213. readPostsForRolls();
  214. setObservers();
  215. hackLatsOptions();
RAW Paste Data
Top