daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 61 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.8.0
  7. // @grant       none
  8. // ==/UserScript==
  9.  
  10. // Things the user can turn on or off, add your new feature to this list
  11. const onOffOptions = [["diceOption", "Dice coloring"],
  12.                      ["edenOption", "Eden Now Playing Banner (not working ;_;)"],
  13.                      ["pyuOption", "Pyu Coloring~"],
  14.                      ["rouletteOption", "Roulette"],
  15.                      ["decideOption", "Decision Coloring"]];
  16.  
  17. // The current settings (will be loaded before other methods are called)
  18. var currentlyEnabledOptions = new Set();
  19.  
  20. // For most new features, you'll want to put a call to your function in this function
  21. function handlePost(post) {
  22.     if (currentlyEnabledOptions.has("diceOption")) {
  23.         var dice = findMultipleShitFromAString(post.innerHTML, /<strong>#(\d*)d(\d+) \((?:[\d +]* )*=? ?(\d+)\)<\/strong>/g);
  24.         for (var j = dice.length - 1; j >= 0; j--) {
  25.             parseRoll(post, dice[j]);
  26.         }
  27.     }
  28.     if (currentlyEnabledOptions.has("pyuOption")) {
  29.         var pyu = findMultipleShitFromAString(post.innerHTML, /<strong>#pyu \(([\d+]*)\)<\/strong>/g);
  30.         for (var j = pyu.length - 1; j >= 0; j--) {
  31.             parsePyu(post, pyu[j]);
  32.         }
  33.     }
  34.     if (currentlyEnabledOptions.has("rouletteOption")) {
  35.         var rouletteDice = findMultipleShitFromAString(post.innerHTML, /#roulette <strong>#d6 \((?:[\d +]* )*=? ?(\d+)\)<\/strong>/g);
  36.         for (var j = rouletteDice.length - 1; j >= 0; j--) {
  37.             parseRoulette(post, rouletteDice[j]);
  38.         }
  39.     }
  40.     if (currentlyEnabledOptions.has("decideOption")) {
  41.         var decide = findMultipleShitFromAString(post.innerHTML, /\[([^\]\[]*)\] <strong>#d([0-9]+) \(([0-9]+)\)<\/strong>/g);
  42.         for (var j = decide.length - 1; j >= 0; j--) {
  43.             parseDecide(post, decide[j]);
  44.         }
  45.     }
  46. }
  47.  
  48. function hackLatsOptions() {
  49.     var options = document.getElementById("options");
  50.     var tab_butts = options.getElementsByClassName("tab-butts")[0];
  51.     var tab_cont = options.getElementsByClassName("tab-cont")[0];
  52.  
  53.     // add checkboxes for each option
  54.     var new_butt /*lewd*/ = "<a class=\"tab-link\" data-id=\"5\">Meguca Userscript</a>";
  55.     var new_cont = "<div data-id=\"5\">";
  56.     for (var i = 0; i < onOffOptions.length; i++) {
  57.         var id = onOffOptions[i][0];
  58.         var name = onOffOptions[i][1];
  59.         new_cont += "<input type=\"checkbox\" name=" + id + " id=" + id + "> <label for=" + id + ">" + name + "</label><br>"
  60.     }
  61.     // Extra descriptions for complicated features, you may want to add something here
  62.     new_cont += "<p>Use <strong>#roulette #d6</strong> to roll the roulette<br>" +
  63.         "Use <strong>[foo, bar, ...] #dn</strong> to make decisions<br>" +
  64.         "<p>Refresh for changes to take effect</div>";
  65.  
  66.     tab_butts.innerHTML += new_butt;
  67.     tab_cont.innerHTML += new_cont;
  68.    
  69.     for (var i = 0; i < onOffOptions.length; i++) {
  70.         var id = onOffOptions[i][0];
  71.         // set the correct intial state
  72.         document.getElementById(id).checked = currentlyEnabledOptions.has(id);
  73.        
  74.         // set all the handler functions
  75.         document.getElementById(id).onchange = function(){
  76.             localStorage.setItem(this.id, this.checked ? "on" : "off");
  77.         };
  78.     }
  79. }
  80.  
  81. function insertCuteIntoCSS() {
  82.     var css = document.createElement("style");
  83.     css.type = "text/css";
  84.     css.innerHTML = ".super_roll { animation: pink_blinker 0.4s linear 100; color: pink; } @keyframes pink_blinker { 50% { color: deeppink } }" +
  85.         ".lewd_roll { animation: lewd_blinker 0.7s linear 57; color: pink; } @keyframes lewd_blinker { 50% { color: #FFD6E1 } }" +
  86.         ".kuso_roll { animation: brown_blinker 1s linear 40; color: #825025; } @keyframes brown_blinker { 50% { opacity: 0.7 } }" +
  87.         ".dubs_roll { animation: blue_blinker 0.4s linear 100; color: aqua; } @keyframes blue_blinker { 50% { color: blue } }" +
  88.         ".trips_roll { animation: yellow_blinker 0.4s linear 100; color: yellow; } @keyframes yellow_blinker { 50% { color: darkorange } }" +
  89.         ".quads_roll { animation: green_blinker 0.4s linear 100; color: lime; } @keyframes green_blinker { 50% { color: darkgreen } }" +
  90.         ".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} }" +
  91.         ".dangerous_roll {font-size: 110%; color: #f00000; }" +
  92.         ".dead_fuck { color: #e55e5e; }" +
  93.         ".thousand_pyu { animation: pyu_blinker 0.4s linear 100; color: aqua; } @keyframes pyu_blinker { 50% { color: white } }";
  94.     document.head.appendChild(css);
  95. }
  96.  
  97. function readPostsForRolls() {
  98.     var posts = document.getElementsByClassName('post-container');
  99.     for (var i = 0; i < posts.length; i++) {
  100.         var post = posts[i];
  101.         handlePost(post);
  102.     }
  103. }
  104.  
  105. function parseRoll(post, die) {
  106.     var n = die[1];
  107.     var m = die[2];
  108.     var x = die[3];
  109.     var divided = (""+x).split(""); //Splits the number into single digits to check for dubs, trips, etc
  110.     if (n == "") {
  111.         n = 1;
  112.     }
  113.  
  114.     var maxRoll = n * m; // because javascript just lets you multiply strings together...
  115.     var before = post.innerHTML.substring(0, die.index);
  116.     var after = post.innerHTML.substring(die.index + die[0].length);
  117.  
  118.     // do nothing for totals below 10, or for n d1s
  119.     if (maxRoll < 10 || m == 1) {
  120.         return;
  121.     }
  122.  
  123.     if (n == 1 && m == x && x == 7777) { // Marrying navy-tan!
  124.         var rollHTML = "<strong class=\"rainbow_roll\"> Congrats! You get to marry navy-tan! " + die[0].substring(8);
  125.         post.innerHTML = before + rollHTML + after;
  126.     } else if (maxRoll == x) {
  127.         var rollHTML = "<strong class=\"super_roll\"> " + die[0].substring(8);
  128.         post.innerHTML = before + rollHTML + after;
  129.     } else if (x == 1) {
  130.         var rollHTML = "<strong class=\"kuso_roll\"> " + die[0].substring(8);
  131.         post.innerHTML = before + rollHTML + after;
  132.     } else if (x == 69 || x == 6969) {
  133.         var rollHTML = "<strong class=\"lewd_roll\"> " + die[0].substring(8);
  134.         post.innerHTML = before + rollHTML + after;
  135.     } else if (checkEm(divided)) {
  136.         switch (divided.length) {
  137.             case 2:
  138.                 var rollHTML = "<strong class=\"dubs_roll\"> " + die[0].substring(8);
  139.                 break;
  140.             case 3:
  141.                 var rollHTML = "<strong class=\"trips_roll\"> " + die[0].substring(8);
  142.                 break;
  143.             case 4:
  144.                 var rollHTML = "<strong class=\"quads_roll\"> " + die[0].substring(8);
  145.                 break;
  146.             default: // QUINTS!!!
  147.                 var rollHTML = "<strong class=\"rainbow_roll\"> " + die[0].substring(8);
  148.                 break;
  149.         }
  150.         post.innerHTML = before + rollHTML + after;
  151.     }
  152. }
  153.  
  154. function parseRoulette(post, die) {
  155.     var postEnding = post.innerHTML.substring(post.innerHTML.length-2);
  156.     var before = post.innerHTML.substring(0, die.index);
  157.     var after = post.innerHTML.substring(die.index + 18);
  158.  
  159.     if (die[1] == 1)
  160.         post.innerHTML = before + "<strong class=\"dead_fuck\"> #roulette " + after;
  161.     else
  162.         post.innerHTML = before + "<strong> #roulette " + after;
  163.  
  164.     // if post ends in "g>" then the strong tag is already set
  165.     if(die[1] == 1 && postEnding != "g>")
  166.         post.innerHTML += "\n <strong class=\"dangerous_roll\"> USER WAS KILLED FOR THIS ROLL</strong>";
  167. }
  168.  
  169. function parsePyu(post, pyu) {
  170.     var n = pyu[1];
  171.     var nsub;
  172.     var before = post.innerHTML.substring(0, pyu.index);
  173.     var after = post.innerHTML.substring(pyu.index + pyu[0].length);
  174.    
  175.     if (n % 1000 == 0) {
  176.         var pyuHTML = "<strong class=\"thousand_pyu\"> 💦 " + pyu[0].substring(8) + " 💦 ";
  177.         post.innerHTML = before + pyuHTML + after;
  178.     }
  179. }
  180.  
  181. function parseDecide(post, decide) {
  182.     var options = decide[1].split(",");
  183.     var n = decide[2];
  184.     var m = decide[3];
  185.    
  186.     var before = post.innerHTML.substring(0, decide.index);
  187.     var after = post.innerHTML.substring(decide.index + decide[0].length);
  188.    
  189.     if (options.length != n) return;
  190.     options[m-1] = "<strong class=\"dubs_roll\">" + options[m-1] + "</strong>";
  191.     var newInner = options.toString();
  192.     var retreivedRoll = " <strong>#d" + n + " (" + m + ")</strong>";
  193.     post.innerHTML = before + newInner + retreivedRoll + after;
  194. }
  195.  
  196. function checkEm(divided) {
  197.     if (divided.length < 2) return false;
  198.  
  199.     var repeatingdigits=true;
  200.     for (var u=divided.length-2; u>=0; u-=1) {
  201.         if (divided[u]!=divided[divided.length-1]) {
  202.             repeatingdigits=false;
  203.             break;
  204.         }
  205.     }
  206.  
  207.     return repeatingdigits;
  208. }
  209.  
  210. function findMultipleShitFromAString(s, re) {
  211.     var result = [];
  212.     var m;
  213.     while (true) {
  214.         m = re.exec(s);
  215.         if (m) result.push(m);
  216.         else break;
  217.     }
  218.     return result;
  219. }
  220.  
  221. function setObservers() {
  222.     var thread = document.getElementById("thread-container");
  223.  
  224.     var observer = new MutationObserver(function(mutations) {
  225.         mutations.forEach(function(mutation) {
  226.             if (mutation.addedNodes.length == 0) return;
  227.             var post = mutation.addedNodes[0].getElementsByClassName("post-container")[0];
  228.  
  229.             var observer2 = new MutationObserver(function(mutations2) {
  230.                 mutations2.forEach(function(mutation2) {
  231.                     if (mutation2.addedNodes.length > 0) {
  232.                         handlePost(post);
  233.                     }
  234.                 });
  235.             });
  236.  
  237.             // configuration of the observer:
  238.             var config = { attributes: true, childList: true, characterData: true };
  239.  
  240.             // pass in the target node, as well as the observer options
  241.             observer2.observe(post.children[0], config);
  242.         });
  243.     });
  244.  
  245.     // configuration of the observer:
  246.     var config = { attributes: true, childList: true, characterData: true };
  247.  
  248.     // pass in the target node, as well as the observer options
  249.     observer.observe(thread, config);
  250. }
  251.  
  252. function getCurrentOptions() {
  253.     for (var i = 0; i < onOffOptions.length; i++) {
  254.         var id = onOffOptions[i][0];
  255.         var setting = localStorage.getItem(id);
  256.         if (setting != "off") {
  257.             currentlyEnabledOptions.add(id);
  258.         }
  259.     }
  260. }
  261.  
  262. getCurrentOptions();
  263. insertCuteIntoCSS();
  264. readPostsForRolls();
  265. setObservers();
  266. hackLatsOptions();
RAW Paste Data
Top