The things I have learned while noodling on a single-page app with my husband over winter vacation have been both illuminating and… well. I’m sorry. I’m so, so sorry.
[code language=”diff”]
Index: js/app.js
===================================================================
— js/app.js (revision 43)
+++ js/app.js (working copy)
@@ -224,6 +224,7 @@
div.className = "uiMessage sent-message";
} else {
div.className = "uiMessage";
+ div.style.backgroundColor = getColorFromString(msg.sender);
}
sender.className = "uiMessageSender";
message.className = "uiMessageContent";
@@ -344,3 +345,8 @@
break;
}
}
+
+function getColorFromString(str) {
+ // I am become Death, the destroyer of worlds.
+ return [ str.slice(0,4), str.slice(4,8), str.slice(8,12) ].map( x => (255 – (Math.floor((x.split(”).reduce((r,c) => { return r + c.charCodeAt(0) }, 0)) / 8))).toString(16)).reduce((r,c) => { return r + c }, ‘#’);
+}
[/code]