lor-colornicks

colorize nicks @ LOR

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        lor-colornicks
// @include     https://www.linux.org.ru/*/*/*
// @include     https://www.linux.org.ru/search.*
// @version     1.4
// @grant       none
// @require     https://code.jquery.com/jquery-3.1.0.min.js
// @namespace https://greasyfork.org/users/134966
// @description colorize nicks @ LOR
// ==/UserScript==

const USE_BORDER = true;
const THIN_BORDERS = false;
const STARS_SAME_AS_NICK = false;
const MIN = 127;  // Minimum value of color component (R, G and B)

String.prototype.toColor = function() {
  hash = this.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);
  c = Math.abs(hash).toString(16);
  r = parseInt(c.substring(0,2), 16);
  g = parseInt(c.substring(2,4), 16);
  b = parseInt(c.substring(4,6), 16);
  if (g < MIN && r < MIN && b < MIN) {
    g += MIN;
    r += MIN;
    b += MIN;
  }
  if (isNaN(r)) r = 128;
  if (isNaN(g)) g = 128;
  if (isNaN(b)) b = 128;
  if (r < 16) r += 16;
  if (g < 16) g += 16;
  if (b < 16) b += 16;
  
  return '#' + r.toString(16) + g.toString(16) + b.toString(16);
}

$(".sign").each(function(i, elem) {
  var e = $(elem);
  var nick = e.children("a:first").text();
  var color1 = nick.toColor();
  var color2 = nick.substring(1).toColor();
  var div = e.closest("article");
  if (USE_BORDER) {
   div.css('border-color', color2);
   div.css('border-style', "solid");
  }
  if (THIN_BORDERS) {
   div.css('border-width', 1);
  }
  e.children("a").css('color', color1);
  
  if (STARS_SAME_AS_NICK) {
   e.children(".stars").css('color', color1);
  } else {
   e.children(".stars").css('color', color2);
  }
});