Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name medukatheguca
- // @namespace megucasoft
- // @description roll highlighter
- // @include https://meguca.org/*
- // @version 0.8.0
- // @grant none
- // ==/UserScript==
- // Things the user can turn on or off, add your new feature to this list
- const onOffOptions = [["diceOption", "Dice coloring"],
- ["edenOption", "Eden Now Playing Banner (not working ;_;)"],
- ["pyuOption", "Pyu Coloring~"],
- ["rouletteOption", "Roulette"],
- ["decideOption", "Decision Coloring"]];
- // The current settings (will be loaded before other methods are called)
- var currentlyEnabledOptions = new Set();
- // For most new features, you'll want to put a call to your function in this function
- function handlePost(post) {
- if (currentlyEnabledOptions.has("diceOption")) {
- var dice = findMultipleShitFromAString(post.innerHTML, /<strong>#(\d*)d(\d+) \((?:[\d +]* )*=? ?(\d+)\)<\/strong>/g);
- for (var j = dice.length - 1; j >= 0; j--) {
- parseRoll(post, dice[j]);
- }
- }
- if (currentlyEnabledOptions.has("pyuOption")) {
- var pyu = findMultipleShitFromAString(post.innerHTML, /<strong>#pyu \(([\d+]*)\)<\/strong>/g);
- for (var j = pyu.length - 1; j >= 0; j--) {
- parsePyu(post, pyu[j]);
- }
- }
- if (currentlyEnabledOptions.has("rouletteOption")) {
- var rouletteDice = findMultipleShitFromAString(post.innerHTML, /#roulette <strong>#d6 \((?:[\d +]* )*=? ?(\d+)\)<\/strong>/g);
- for (var j = rouletteDice.length - 1; j >= 0; j--) {
- parseRoulette(post, rouletteDice[j]);
- }
- }
- if (currentlyEnabledOptions.has("decideOption")) {
- var decide = findMultipleShitFromAString(post.innerHTML, /\[([^\]\[]*)\] <strong>#d([0-9]+) \(([0-9]+)\)<\/strong>/g);
- for (var j = decide.length - 1; j >= 0; j--) {
- parseDecide(post, decide[j]);
- }
- }
- }
- function hackLatsOptions() {
- var options = document.getElementById("options");
- var tab_butts = options.getElementsByClassName("tab-butts")[0];
- var tab_cont = options.getElementsByClassName("tab-cont")[0];
- // add checkboxes for each option
- var new_butt /*lewd*/ = "<a class=\"tab-link\" data-id=\"5\">Meguca Userscript</a>";
- var new_cont = "<div data-id=\"5\">";
- for (var i = 0; i < onOffOptions.length; i++) {
- var id = onOffOptions[i][0];
- var name = onOffOptions[i][1];
- new_cont += "<input type=\"checkbox\" name=" + id + " id=" + id + "> <label for=" + id + ">" + name + "</label><br>"
- }
- // Extra descriptions for complicated features, you may want to add something here
- new_cont += "<p>Use <strong>#roulette #d6</strong> to roll the roulette<br>" +
- "Use <strong>[foo, bar, ...] #dn</strong> to make decisions<br>" +
- "<p>Refresh for changes to take effect</div>";
- tab_butts.innerHTML += new_butt;
- tab_cont.innerHTML += new_cont;
- for (var i = 0; i < onOffOptions.length; i++) {
- var id = onOffOptions[i][0];
- // set the correct intial state
- document.getElementById(id).checked = currentlyEnabledOptions.has(id);
- // set all the handler functions
- document.getElementById(id).onchange = function(){
- localStorage.setItem(this.id, this.checked ? "on" : "off");
- };
- }
- }
- function insertCuteIntoCSS() {
- var css = document.createElement("style");
- css.type = "text/css";
- css.innerHTML = ".super_roll { animation: pink_blinker 0.4s linear 100; color: pink; } @keyframes pink_blinker { 50% { color: deeppink } }" +
- ".lewd_roll { animation: lewd_blinker 0.7s linear 57; color: pink; } @keyframes lewd_blinker { 50% { color: #FFD6E1 } }" +
- ".kuso_roll { animation: brown_blinker 1s linear 40; color: #825025; } @keyframes brown_blinker { 50% { opacity: 0.7 } }" +
- ".dubs_roll { animation: blue_blinker 0.4s linear 100; color: aqua; } @keyframes blue_blinker { 50% { color: blue } }" +
- ".trips_roll { animation: yellow_blinker 0.4s linear 100; color: yellow; } @keyframes yellow_blinker { 50% { color: darkorange } }" +
- ".quads_roll { animation: green_blinker 0.4s linear 100; color: lime; } @keyframes green_blinker { 50% { color: darkgreen } }" +
- ".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} }" +
- ".dangerous_roll {font-size: 110%; color: #f00000; }" +
- ".dead_fuck { color: #e55e5e; }" +
- ".thousand_pyu { animation: pyu_blinker 0.4s linear 100; color: aqua; } @keyframes pyu_blinker { 50% { color: white } }";
- document.head.appendChild(css);
- }
- function readPostsForRolls() {
- var posts = document.getElementsByClassName('post-container');
- for (var i = 0; i < posts.length; i++) {
- var post = posts[i];
- handlePost(post);
- }
- }
- function parseRoll(post, die) {
- var n = die[1];
- var m = die[2];
- var x = die[3];
- var divided = (""+x).split(""); //Splits the number into single digits to check for dubs, trips, etc
- if (n == "") {
- n = 1;
- }
- var maxRoll = n * m; // because javascript just lets you multiply strings together...
- var before = post.innerHTML.substring(0, die.index);
- var after = post.innerHTML.substring(die.index + die[0].length);
- // do nothing for totals below 10, or for n d1s
- if (maxRoll < 10 || m == 1) {
- return;
- }
- if (n == 1 && m == x && x == 7777) { // Marrying navy-tan!
- var rollHTML = "<strong class=\"rainbow_roll\"> Congrats! You get to marry navy-tan! " + die[0].substring(8);
- post.innerHTML = before + rollHTML + after;
- } else if (maxRoll == x) {
- var rollHTML = "<strong class=\"super_roll\"> " + die[0].substring(8);
- post.innerHTML = before + rollHTML + after;
- } else if (x == 1) {
- var rollHTML = "<strong class=\"kuso_roll\"> " + die[0].substring(8);
- post.innerHTML = before + rollHTML + after;
- } else if (x == 69 || x == 6969) {
- var rollHTML = "<strong class=\"lewd_roll\"> " + die[0].substring(8);
- post.innerHTML = before + rollHTML + after;
- } else if (checkEm(divided)) {
- switch (divided.length) {
- case 2:
- var rollHTML = "<strong class=\"dubs_roll\"> " + die[0].substring(8);
- break;
- case 3:
- var rollHTML = "<strong class=\"trips_roll\"> " + die[0].substring(8);
- break;
- case 4:
- var rollHTML = "<strong class=\"quads_roll\"> " + die[0].substring(8);
- break;
- default: // QUINTS!!!
- var rollHTML = "<strong class=\"rainbow_roll\"> " + die[0].substring(8);
- break;
- }
- post.innerHTML = before + rollHTML + after;
- }
- }
- function parseRoulette(post, die) {
- var postEnding = post.innerHTML.substring(post.innerHTML.length-2);
- var before = post.innerHTML.substring(0, die.index);
- var after = post.innerHTML.substring(die.index + 18);
- if (die[1] == 1)
- post.innerHTML = before + "<strong class=\"dead_fuck\"> #roulette " + after;
- else
- post.innerHTML = before + "<strong> #roulette " + after;
- // if post ends in "g>" then the strong tag is already set
- if(die[1] == 1 && postEnding != "g>")
- post.innerHTML += "\n <strong class=\"dangerous_roll\"> USER WAS KILLED FOR THIS ROLL</strong>";
- }
- function parsePyu(post, pyu) {
- var n = pyu[1];
- var nsub;
- var before = post.innerHTML.substring(0, pyu.index);
- var after = post.innerHTML.substring(pyu.index + pyu[0].length);
- if (n % 1000 == 0) {
- var pyuHTML = "<strong class=\"thousand_pyu\"> 💦 " + pyu[0].substring(8) + " 💦 ";
- post.innerHTML = before + pyuHTML + after;
- }
- }
- function parseDecide(post, decide) {
- var options = decide[1].split(",");
- var n = decide[2];
- var m = decide[3];
- var before = post.innerHTML.substring(0, decide.index);
- var after = post.innerHTML.substring(decide.index + decide[0].length);
- if (options.length != n) return;
- options[m-1] = "<strong class=\"dubs_roll\">" + options[m-1] + "</strong>";
- var newInner = options.toString();
- var retreivedRoll = " <strong>#d" + n + " (" + m + ")</strong>";
- post.innerHTML = before + newInner + retreivedRoll + after;
- }
- function checkEm(divided) {
- if (divided.length < 2) return false;
- var repeatingdigits=true;
- for (var u=divided.length-2; u>=0; u-=1) {
- if (divided[u]!=divided[divided.length-1]) {
- repeatingdigits=false;
- break;
- }
- }
- return repeatingdigits;
- }
- function findMultipleShitFromAString(s, re) {
- var result = [];
- var m;
- while (true) {
- m = re.exec(s);
- if (m) result.push(m);
- else break;
- }
- return result;
- }
- function setObservers() {
- var thread = document.getElementById("thread-container");
- var observer = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- if (mutation.addedNodes.length == 0) return;
- var post = mutation.addedNodes[0].getElementsByClassName("post-container")[0];
- var observer2 = new MutationObserver(function(mutations2) {
- mutations2.forEach(function(mutation2) {
- if (mutation2.addedNodes.length > 0) {
- handlePost(post);
- }
- });
- });
- // configuration of the observer:
- var config = { attributes: true, childList: true, characterData: true };
- // pass in the target node, as well as the observer options
- observer2.observe(post.children[0], config);
- });
- });
- // configuration of the observer:
- var config = { attributes: true, childList: true, characterData: true };
- // pass in the target node, as well as the observer options
- observer.observe(thread, config);
- }
- function getCurrentOptions() {
- for (var i = 0; i < onOffOptions.length; i++) {
- var id = onOffOptions[i][0];
- var setting = localStorage.getItem(id);
- if (setting != "off") {
- currentlyEnabledOptions.add(id);
- }
- }
- }
- getCurrentOptions();
- insertCuteIntoCSS();
- readPostsForRolls();
- setObservers();
- hackLatsOptions();
Add Comment
Please, Sign In to add comment