Skip to content

Instantly share code, notes, and snippets.

@Rohansi
Created January 25, 2016 03:38
Show Gist options
  • Save Rohansi/0a6c16df2ace63f692ca to your computer and use it in GitHub Desktop.
Save Rohansi/0a6c16df2ace63f692ca to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name RohBot Color Randomizer
// @version 0.1
// @description try to take over the world!
// @author Rohansi
// @match https://rohbot.net/
// @grant GM_addStyle
// @require https://raw.githubusercontent.com/garycourt/murmurhash-js/0197ce38bedac0e05f40b9d7152095d06db8292c/murmurhash3_gc.js
// ==/UserScript==
var seed = 7;
var cache = {};
function getColor(userId) {
var hash = murmurhash3_32_gc(userId || "", seed);
var colorName = "rand-" + hash;
if (cache.hasOwnProperty(hash))
return colorName;
// get a positive value for the hue
var deg = hash % 360;
var h = deg < 0 ? 360 + deg : deg;
// default L is 75
var l = 75;
// half of the hues are too light, for those we
// decrease lightness
if(h >= 30 && h <= 210) {
l = 50;
}
// keep saturation above 50
var s = 50 + Math.abs(hash) % 50;
GM_addStyle(".styled-names ." + colorName + " { color: hsl(" + h + "," + s + "%," + l + "%); }");
cache[hash] = true;
return colorName;
}
chatMgr.lineFilter.add(function (line, prepend, e) {
switch (line.Type) {
case "chat":
if (!line.SenderStyle) line.SenderStyle = getColor(line.SenderId);
break;
case "state":
if (!line.ForStyle) line.ForStyle = getColor(line.ForId);
if (!line.ByStyle && line.ById) line.ByStyle = getColor(line.ById);
break
}
});
chatMgr.userFilter.add(function (user, e) {
if (!user.Style) user.Style = getColor(user.UserId);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment