Chirrox / VACalculator

// ==UserScript==
// @name        VACalculator
// @author   ziep
// @version  2.1.39
// @icon      https://resources.patchworkklub.sk/rapp/icon.png
// @description Add a mini version of the Verbal abuse calculator as a dialog box
// @require  http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
// @require  https://resources.patchworkklub.sk/js/jquery-2.2.4.min.js
// @require  https://raw.githubusercontent.com/mckamey/countdownjs/master/countdown.min.js
// @require  https://raw.githubusercontent.com/jeresig/jquery.hotkeys/master/jquery.hotkeys.js
// @require  https://resources.patchworkklub.sk/js/jquery-cookie.js
// @require  https://raw.githubusercontent.com/bunkat/later/master/later.min.js
// @require  https://raw.githubusercontent.com/jeresig/jquery.hotkeys/master/jquery.hotkeys.js
// @require  https://rap.heroesofnewerth.com/js/jquery.dataTables.min.js
// @require  https://rap.heroesofnewerth.com/js/dataTables.bootstrap.min.js
// @require  https://rap.heroesofnewerth.com/js/moment.js
// @require  https://code.jquery.com/ui/1.12.1/jquery-ui.js
// @grant       GM_addStyle
// @match     *://rap.heroesofnewerth.com/chat.php*
// @updateURL https://openuserjs.org/meta/Chirrox/VACalculator.meta.js
// @downloadURL https://openuserjs.org/install/Chirrox/VACalculator.user.js
// @copyright 2020, ziep (https://openuserjs.org/users/ziep) - More words added by Chriss, code altered by Elf01.
// @license 0BSD

// ==/UserScript==
/*- The @grant directive is needed to work around a design change
    introduced in GM 1.0.   It restores the sandbox.
*/
var $data = ['pidr','пидр','pider','niger','nigg er','f a g','boiola','viado','baitola','viadinho','f@g','niga','schwuchtel','пидар','hope you die','пидор','пидарас', 'kill ur self', 'kill urself', 'kill yourself','kill your self', 'kys', 'beaner', 'bög', 'chink', 'coon', 'dothead', 'dune coon', 'fag', 'faggit', 'fag', 'fascina', 'fgt', 'gandon', 'gook', 'ibne', 'indio', 'macaco', 'marica', 'maricon', 'negro', 'nggr', 'nigga', 'peder', 'pidar', 'pidor', 'nigger', 'spic', "wetback", "wet back", "untermensch", "nibba"];
var $extra = ['fkcing','tarfds','tarsh','wh0rte','braidnead','spastic','retsrd','bastard','fucker','fucking','bi tch','b itch','bit ch','bitc h','retard','cu nt','c unt','cun t','dolboeb','imbicile','idioyt','mfk','stuopid','rtyearsd','stupiod','wgh0rfe','wh0re','rteards','beatch','trasyh','idoit','subhuman','stuypid','horugne','imb3cil','d0g','doog','twat','sutpid','t4rash','cocksucker','trasg','btch','trahs','suck a','basterd','тупой','horunge','hurensohn','hurenshon','sck a dik','fackin','fk u','bich','trsh','traghs','fducking','trasss','shiit','atuist','brain','garbag','reatrds','shiet','шлюхи','рак','мусор','family','nobrain','no brain','di ck','blyat','dolbaeb','que te jodan','cracudo','vaca','hdp','ctmr','csmr','piranha','putinha','vai tomar no c','lixo','vsf','vai se fuder','arrombado','fkign','down syndrom','downsyndrom','morron','ctmr','hijo de perra','stupit','ni gger','idipots','musor','coock','biitch','whoore','twaats','mother','covid','monkets','mon key','family die','die from','iiot','embicle','b12ch','хуеглот','diumb','d1ck','faking','sh1t','retyatrd','suck my','facker','faken','gay','homo','fcn','dead brain','deadbrain','imebcils','fdp','fck','шлюха','хуесо','mental','Autis','huisos','yebak','uebok','nahooi','pizda','pizdec','mudak','fkin','braind','slave','caralho','уебак','сука','fkn','animal','ape','bitch','meirda','mierda','puta','hdp','csm','basura','cancer', "aids", "corona", "ebola", "shit",'fu','fuck you','dog','tard','slut','whore','cunt','moron','braindead','lowiq','iq','inbred','mongo','idiot','nazi','huesos','cyka','suka','trash','nahui','garbage','scum','asshole','dumb','stupid','dick','pussy','rat','donkey','monkey','ape','animal','imbecil','ctm','autist'];
var $VACalcDialog;
function addHighlight() {
  $("head").append('<style type="text/css">' +
    '.t1Word{color:#ff0000;}' +
    '.extra_words{color: #FFA500;}')

  $(".chatAdd").each(function () {

    var new_elem = '';
    for (var i = 0; i < Math.max($data.length, $extra.length); i++) {
      if (i < $data.length && $(this).text().toLowerCase().includes($data[i])) {
        var reg = new RegExp($data[i], 'gi');
        if (new_elem.length > 0) {
          new_elem = new_elem.replaceAll(reg, ('<span class="t1Word">$&</span>'));
        }
        else {
          new_elem = '<span class="chatAdd" style="color: rgb(255,255,255);">' + $(this).text().replaceAll(reg, ('<span class="t1Word">$&</span>')) + '</span>';
        }
      }
      if (i < $extra.length && $(this).text().toLowerCase().includes($extra[i])) {
        var ereg = new RegExp($extra[i], 'gi');
        if (new_elem.length > 0) {
          new_elem = new_elem.replaceAll(ereg, ('<span class="extra_words">$&</span>'));
        }
        else {
          new_elem = '<span class="chatAdd" style="color: rgb(255,255,255);">' + $(this).text().replaceAll(ereg, ('<span class="extra_words">$&</span>')) + '</span>';
        }
      }
      else if (new_elem.length) {
        continue;
      }
    }
    if (new_elem.length) {
      $(this).replaceWith(new_elem);
    }
  });
}
(function () {
  $('head').append('<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">'+ //dunno if Smilie grief me but I need jquery 1.12.1 xD
    "<style type='text/css'>" +
    ".guilty{color:red;display:inline-block;font-size:1.5rem;}" +
    ".warning{color:#ff9000;display:inline-block;font-size:1.5rem;}" +
    ".innocent{color:green;display:inline-block;font-size:1.5rem;}" +
    ".result{font-size:1.5rem;}" +
    ".t1Word{color:#ff0000;}" +
    "input[type='number'] {-webkit-appearance: textfield;-moz-appearance: textfield;appearance: textfield;}input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none;}" +
    //                    "@import 'https://fonts.googleapis.com/css?family=Lato:400,400italic,700|Sansita+One;max-width:100%;margin:25px;font-size:calc(1rem + 0.25vh);overflow:auto"+
    "</style>");
  $("body").append('                                                          \
    <div id="gmPopupContainer" title = "VACalculator" scrolling = "yes" class="gmPopupContainer"> \
    <form><div priorsButton><p style="display: inline-block;">Priors within the last 9 months?</p>\
    <label for="yes" style="cursor: pointer;">\
    <input type="radio" style="display: inline-block;cursor: pointer;" id="yes" name="priors" value="Yes">Yes</label>\
    <label for="no" style="cursor: pointer;">\
    <input type="radio" style="display: inline-block;cursor:pointer;" id="no" name="priors" value="No" checked>No</label>\
    <br></div></form>\
    <body><div calc><input style="cursor: pointer;" type="Button" id="resetButton" value="Reset" title="Set all fields to 0">\
    <div inputBoxes style="width: 70%";>\
    <div>How many T1: <input class="tier" id="t1" type="number" step="1" min="0" required value="0" /><input style="cursor: pointer;" type="Button" class="add" value="+1">\
    &nbsp&nbsp<input style="cursor: pointer;" class="sub" type="Button" value="-1"></div>\
    <div><br><br><br>How many T2: <input class="tier" id="t2" type="number" step="1" min="0" required value="0" />\
    <input style="cursor: pointer;" type="Button" class="add" value="+1">&nbsp&nbsp<input style="cursor: pointer;" type="Button" class="sub" value="-1"></div>\
    <div><br><br><br>How many T3: <input class="tier" id="t3" type="number" step="1" min="0" required value="0" />\
    <input style="cursor: pointer;" type="Button" class="add" value="+1" >&nbsp&nbsp<input style="cursor: pointer;" type="Button" class="sub" value="-1"></div>\
    <div><br><br><br>How many T4: <input class="tier" id="t4" type="number" step="1" min="0" required value="0" />\
    <input style="cursor: pointer;" type="Button" class="add" value="+1" >&nbsp&nbsp<input style="cursor: pointer;" type="Button" class="sub" value="-1" ></div>\
    </div><br><br></div> \
    </head></body></html>\
    <input style="cursor: pointer;" type="Button" id="calcButton" value="Calculate"><br>\
    </div> \
    ');

  $(function () {
    $VACalcDialog = $("#gmPopupContainer").dialog({
      autoOpen: false,
      maxWidth: 1000,
      maxHeight: 1000,
      height: 760,
      width: 700,
    });
  });

  $(function () {
      addHighlight();
      addButton("VA calculator");

    function addButton(text, onclick, cssObj) {
      cssObj = cssObj || {
        position: "fixed",
        top: "680px",
        right: "200px",
        "z-index": "999",
        fontWeight: "600",
        fontSize: "14px",
        cursor: "pointer",
        //backgroundColor: "#00cccc",
        color: "black",
        border: "none",
        padding: "10px 20px"
      };
      let button = document.createElement("button"),
        btnStyle = button.style;
      document.body.appendChild(button);
      button.innerHTML = text;
      // Settin function for button when it is clicked.
      button.onclick = selectReadFn;
      Object.keys(cssObj).forEach((key) => (btnStyle[key] = cssObj[key]));
      return button;
    }

    function selectReadFn() {
      $VACalcDialog.dialog("open");
    }
  });

  $("#calcButton").click(function () {
    $('.result').remove();
    //<!-- variable declarations-->
    var $t1 = parseFloat($("#t1").val());
    var $t2 = parseFloat($("#t2").val());
    var $t3 = parseFloat($("#t3").val());
    var $t4 = parseFloat($("#t4").val());
    //<!--$op = document.getElementById("opr").value;-->
    var $t1WarningRatio = 7;
    var $t2WarningRatio = 2.33334;
    var $t3WarningRatio = 1.4;

    var $t1GuiltyRatio = 4.5;
    var $t2GuiltyRatio = 1.8;
    var $t3GuiltyRatio = 1.286;
    var $priors = $('#yes').is(':checked');
    var $hasPriors = '';
    var $need = '9';
    var $totalLinesWarning = (($t1 * $t1WarningRatio) + ($t2 * $t2WarningRatio) + ($t3 * $t3WarningRatio) + $t4).toFixed(2);
    var $totalLinesGuilty = (($t1 * $t1GuiltyRatio) + ($t2 * $t2GuiltyRatio) + ($t3 * $t3GuiltyRatio) + $t4).toFixed(2);

    var $guilty = ($totalLinesGuilty >= 9);
    var $warning = ($totalLinesWarning >= 7);
    if ($priors) {
      $guilty = ($guilty || $warning);
      $totalLinesGuilty = $totalLinesWarning;
      $hasPriors = ' with priors';
      $need = '7';
    }
    if ($guilty) {
      $(this).parent().append('<div class="result"><b>VERDICT</b>: <p class="guilty">Guilty!</p></p>');
      $(this).parent().append('<div class="result">&#9989; Sufficient for <p class="guilty">Guilty' + $hasPriors + '! </p> (<p class ="guilty">Guilty</p> score of ' +
        $totalLinesGuilty + '/' + $need + ')</div>'
      );
    }
    else if ($warning) {
      $(this).parent().append('<div class="result"><b>VERDICT</b>: <p class="warning">Warning!</p></p>');
      $(this).parent().append('<div class="result">&#10060; Insufficient for <p class="guilty">Guilty! </p> (<p class ="guilty">Guilty</p> score of ' +
        $totalLinesGuilty + '/' + $need + ')</div>'
      );
      $(this).parent().append('<div class="result">&#9989; Sufficient for <p class="warning">Warning! </p> (<p class ="warning">Warning</p> score of ' +
        $totalLinesWarning + '/7' + ')</div>'
      );
    }
    else {
      $(this).parent().append('<div class="result"><b>VERDICT</b>: <p class="innocent">Innocent!</p></p>');
      $(this).parent().append('<div class="result">&#10060; Insufficient for <p class="guilty">Guilty! </p> (<p class ="guilty">Guilty</p> score of ' +
        $totalLinesGuilty + '/' + $need + ')</div>');
      $(this).parent().append('<div class="result">&#10060; Insufficient for <p class="warning">Warning! </p> (<p class ="warning">Warning</p> score of ' +
        $totalLinesWarning + '/7' + ')</div>'
      );
    }
  });
  $("#resetButton").click(function () {
    $(".tier").val('0');
    $(".result").remove();
    $("#no").prop("checked", true);
  });
  $('.tier').on('change', function (e) {
    if (!((parseFloat($(this).val()) >= 0) && (parseFloat($(this).val()) <= 100))) {
      $(this).val('0')
    }
  })
  $('.add').click(function () {
    var $counter = parseFloat($(this).parent().children(".tier").val()) + 1;
    $(this).parent().children(".tier").val($counter);
  });
  $('.sub').click(function () {
    var $counter = parseFloat($(this).parent().children(".tier").val()) - 1;
    if (($counter) >= 0) {
      $(this).parent().children(".tier").val($counter);
    }
  });
})();