<commit_before>// ==UserScript==
// @name        MetaFilter User Makeup
// @namespace   https://github.com/roukaour/
// @description Assigns each MetaFilter user a random but consistent color and symbol.
// @include     *://*.metafilter.com/*
// @version     1.1
// @grant       none
// @run-at      document-end
// ==/UserScript==

// Inspired by valrus' Colorful Comments
// https://metatalk.metafilter.com/24039/Color-Comments-By-User
// https://github.com/valrus/mefi-comment-colors/

function hashCode(s) {
	// String#hashCode from Java
	var hash = 0;
	for (var i = 0; i < s.length; i++) {
		hash = s.charCodeAt(i) + ((hash << 5) - hash);
	}
	return hash;
} 

function hashToColorSpan(x) {
	// Based on Cristian Sanchez's code:
	// http://stackoverflow.com/a/3426956/70175
	var fore = (x & 0xFFFFFF).toString(16).toUpperCase();
	fore = "00000".substring(0, 6 - fore.length) + fore;
	var r = (x & 0xFF0000) >> 16, g = (x & 0xFF00) >> 8, b = x & 0xFF;
	var luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
	var back = luma >= 165 ? "000" : "FFF";
	return "<span style='color: #" + fore + "; background: #" + back + ";'>";
}

function hashToSymbol(x) {
	var symbols = "●■▲▼◆▰★✪♠♣♥♦◈◉✠✿";
	var i = (x & 0xF000000) / 0x1000000;
	return symbols.substring(i, i + 1);
}

function assignColors() {
	var bylines = document.getElementsByClassName('smallcopy');
	var i = bylines.length;
	while (i--) {
		var byline = bylines[i];
		if (!byline.innerHTML.startsWith("posted by")) continue;
		var userlink = byline.getElementsByTagName('a')[0];
		var username = userlink.innerHTML;
		var hash = hashCode(username);
		var colorSpan = hashToColorSpan(hash);
		var symbol = hashToSymbol(hash);
		userlink.innerHTML = colorSpan + "<big>" + symbol + "</big> " +
			username + "</span>";<commit_msg>Color background, not text.<commit_after>// ==UserScript==
// @name        MetaFilter User Makeup
// @namespace   https://github.com/roukaour/
// @description Assigns each MetaFilter user a random but consistent color and symbol.
// @include     *://*.metafilter.com/*
// @version     1.2
// @grant       none
// @run-at      document-end
// ==/UserScript==

// Inspired by valrus' Colorful Comments
// https://metatalk.metafilter.com/24039/Color-Comments-By-User
// https://github.com/valrus/mefi-comment-colors/

function hashCode(s) {
	// String#hashCode from Java
	var hash = 0;
	for (var i = 0; i < s.length; i++) {
		hash = s.charCodeAt(i) + ((hash << 5) - hash);
	}
	return hash;
} 

function hashToColorSpan(x) {
	// Based on <NAME>'s code:
	// http://stackoverflow.com/a/3426956/70175
	var color = (x & 0xFFFFFF).toString(16).toUpperCase();
	color = "00000".substring(0, 6 - color.length) + color;
	var r = (x & 0xFF0000) >> 16, g = (x & 0xFF00) >> 8, b = x & 0xFF;
	var luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
	var contrast = luma >= 165 ? "000" : "FFF";
	return "<span style='background: #" + color + "; color: #" + contrast + ";'>";
}

function hashToSymbol(x) {
	var symbols = "●■▲▼◆▰★✪♠♣♥♦◈◉✠✿";
	var i = (x & 0xF000000) / 0x1000000;
	return symbols.substring(i, i + 1);
}

function assignColors() {
	var bylines = document.getElementsByClassName('smallcopy');
	var i = bylines.length;
	while (i--) {
		var byline = bylines[i];
		if (!byline.innerHTML.startsWith("posted by")) continue;
		var userlink = byline.getElementsByTagName('a')[0];
		var username = userlink.innerHTML;
		var hash = hashCode(username);
		var colorSpan = hashToColorSpan(hash);
		var symbol = hashToSymbol(hash);
		userlink.innerHTML = colorSpan + "<big>" + symbol + "</big> " +
			username + "</span>";
{'fraction_non_alphanumeric': 0.18461538461538463, 'fraction_numerical': 0.04587412587412588, 'mean_word_length': 3.371638141809291, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 22, 'https://': 6, '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': '176932', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1320, 'n_words': 321}