<commit_before>/* jslint browser: true */
/* global app, Textual */

/* Defined in: "Textual.app -> Contents -> Resources -> JavaScript -> API -> core.js" */

var mappedSelectedUsers = [];
var rs                  = {}; // room state

/* Set the default statuses for everything tracked in the roomState */
rs.previousNickCount       = 1;
rs.previousNickDelete      = false;
rs.previousNickRepeatCount = 10; // How frequently to repeat a nick if they have many lines in a row

var NickColorGenerator = (function () {
  'use strict';

  function NickColorGenerator(message) {
    var i, inlineNicks, nick;

    //Start alternative nick colouring procedure
    var selectNick = message.querySelector('.sender');
    selectNick.removeAttribute('colornumber');
    var nickcolor = this.generateColorFromHash(selectNick.getAttribute('nickname'));

    selectNick.style.color = nickcolor;

    inlineNicks = message.querySelectorAll('.inline_nickname');
    if (message.getAttribute('ltype') === 'action') {
      message.querySelector('.message').style.color = nickcolor;
    }
    for (i = 0; i < inlineNicks.length; i++) {
      inlineNicks[i].removeAttribute('colornumber');
      nick = inlineNicks[i].innerHTML;
      if (inlineNicks[i].getAttribute('mode').length > 0) {
        nick = nick.replace(inlineNicks[i].getAttribute('mode'), '');
      }
      inlineNicks[i].style.color = this.generateColorFromHash(nick);
    }
  }

/*   Attempts to clean up a nickname by removing alternate characters from the end;
     nc_ becomes nc, avidal` becomes avidal */
  NickColorGenerator.prototype.sanitiseNickname = function (nick) {
    nick = nick.toLowerCase();
    nick = nick.replace(/[`_-]+$/, ''); // typically `, _, and - are used on the end of a nick
    nick = nick.replace(/|.*$/, ''); // remove |<anything> from the end
    return nick;
  };

  NickColorGenerator.prototype.generateHashFromNickname = function (nick) {
    var cleaned = this.sanitiseNickname(nick), h = 0, i;

    for (i = 0; i < cleaned.length; i++) {
      h = cleaned.charCodeAt(i) + (h << 6) + (h << 16) - h;
    }
    return h;
  };

  NickColorGenerator.prototype.generateColorFromHash = function (nick) {
    var nickhash = this.generateHashFromNickname(nick);
    var deg      = nickhash % 360;
    var h        = deg < 0 ? 360 + deg : deg;
    var l        = Math.abs(nickhash) % 110;
    var s;

    // don't use the blue hues
    if (h >= 240 && h <= 270) {
      h += 30;
    }
    if (h < 240 && h >= 210) {
      h -= 30;<commit_msg>More tweaks to nick color generation<commit_after>/* jslint browser: true */
/* global app, Textual */

/* Defined in: "Textual.app -> Contents -> Resources -> JavaScript -> API -> core.js" */

var mappedSelectedUsers = [];
var rs                  = {}; // room state

/* Set the default statuses for everything tracked in the roomState */
rs.previousNickCount       = 1;
rs.previousNickDelete      = false;
rs.previousNickRepeatCount = 10; // How frequently to repeat a nick if they have many lines in a row

var NickColorGenerator = (function () {
  'use strict';

  function NickColorGenerator(message) {
    var i, inlineNicks, nick;

    //Start alternative nick colouring procedure
    var selectNick = message.querySelector('.sender');
    selectNick.removeAttribute('colornumber');
    var nickcolor = this.generateColorFromHash(selectNick.getAttribute('nickname'));

    selectNick.style.color = nickcolor;

    inlineNicks = message.querySelectorAll('.inline_nickname');
    if (message.getAttribute('ltype') === 'action') {
      message.querySelector('.message').style.color = nickcolor;
    }
    for (i = 0; i < inlineNicks.length; i++) {
      inlineNicks[i].removeAttribute('colornumber');
      nick = inlineNicks[i].innerHTML;
      if (inlineNicks[i].getAttribute('mode').length > 0) {
        nick = nick.replace(inlineNicks[i].getAttribute('mode'), '');
      }
      inlineNicks[i].style.color = this.generateColorFromHash(nick);
    }
  }

/*   Attempts to clean up a nickname by removing alternate characters from the end;
     nc_ becomes nc, avidal` becomes avidal */
  NickColorGenerator.prototype.sanitiseNickname = function (nick) {
    nick = nick.toLowerCase();
    nick = nick.replace(/[`_-]+$/, ''); // typically `, _, and - are used on the end of a nick
    nick = nick.replace(/|.*$/, ''); // remove |<anything> from the end
    return nick;
  };

  NickColorGenerator.prototype.generateHashFromNickname = function (nick) {
    var cleaned = this.sanitiseNickname(nick), h = 0, i;

    for (i = 0; i < cleaned.length; i++) {
      h = cleaned.charCodeAt(i) + (h << 6) + (h << 16) - h;
    }
    return h;
  };

  NickColorGenerator.prototype.generateColorFromHash = function (nick) {
    var nickhash = this.generateHashFromNickname(nick);
    var deg      = nickhash % 360;
    var h        = deg < 0 ? 360 + deg : deg;
    var l        = Math.abs(nickhash) % 110;
    var s;

    // don't use the blue and purple hues
    if (h >= 255 && h <= 290) {
      h += 45;
    }
    if (h < 255 && h >= 210) {
      h -= 45;
{'fraction_non_alphanumeric': 0.13998422712933753, 'fraction_numerical': 0.014195583596214511, 'mean_word_length': 2.9143518518518516, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5056446', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1523, 'n_words': 426}