Coloured nicks
authorDarren <darren@darrenwhitlen.com>
Tue, 13 Sep 2011 12:35:21 +0000 (13:35 +0100)
committerDarren <darren@darrenwhitlen.com>
Tue, 13 Sep 2011 12:35:21 +0000 (13:35 +0100)
js/util.js

index c840c62024b569c1a669e912dcecab526384afa1..c67e2ad325bc3dd50c26a0c2bd8a35d2aa34c67d 100644 (file)
@@ -225,6 +225,42 @@ var plugins = [
                }
        },
 
+    {
+        name: "nick_colour",
+        onaddmsg: function (event, opts) {
+            if (!event.msg) {
+                return event;
+            }
+
+            if (typeof front.tabviews[event.tabview].nick_colours === 'undefined') {
+                front.tabviews[event.tabview].nick_colours = {};
+            }
+
+            if (typeof front.tabviews[event.tabview].nick_colours[event.nick] === 'undefined') {
+                front.tabviews[event.tabview].nick_colours[event.nick] = this.randColour();
+            }
+            
+            var c = front.tabviews[event.tabview].nick_colours[event.nick];
+            event.nick = '<span style="color:' + c + ';">' + event.nick + '</span>';
+            
+            return event;
+        },
+
+
+
+        randColour: function () {
+            var h = this.rand(-250, 0);
+            var s = this.rand(30, 100);
+            var l = this.rand(20, 70);
+            return 'hsl(' + h + ',' + s + '%,' + l + '%)';
+        },
+
+
+        rand: function (min, max) {
+            return parseInt(Math.random() * (max-min+1), 10) + min;
+        }
+    },
+
        {
                name: "kiwitest",
                oninit: function (event, opts) {