-function Colourise(line, entity, execfn) {
+qwebirc.ui.Colourise = function(line, entity, execfn, cmdfn, window) {
var fg;
var bg;
var underline = false;
var bold = false;
-
+ var autoNickColour = false;
+
var out = [];
var xline = line.split("");
var element = document.createElement("span");
}
function emitEndToken() {
+ var data = "";
if(out.length > 0) {
- urlificate(element, out.join(""), execfn);
+ var data = qwebirc.ui.urlificate(element, out.join(""), execfn, cmdfn, window);
entity.appendChild(element);
out = [];
}
element = document.createElement("span");
+ return data;
}
+
function emitStartToken() {
- classes = []
+ if(autoNickColour)
+ return element;
+
+ var classes = []
if(fg != undefined)
classes.push("Xc" + fg);
if(bg != undefined)
element.className = classes.join(" ");
}
- for(i=0;i<xline.length;i++) {
+ var nickColouring = window.parentObject.uiOptions.NICK_COLOURS; /* HACK */
+ var capturingNick = false;
+ for(var i=0;i<xline.length;i++) {
var lc = xline[i];
+
+ if(nickColouring) {
+ if(!capturingNick) {
+ if(lc == "\x00") {
+ capturingNick = true;
+ emitEndToken();
+ continue;
+ }
+ } else {
+ if(lc != "\x00") {
+ out.push(lc);
+ } else {
+ autoNickColour = true;
+ var e = emitStartToken();
+ var text = emitEndToken();
+
+ var c = text.toHSBColour(window.client);
+ if($defined(c))
+ e.style.color = c.rgbToHex();
+ capturingNick = autoNickColour = false;
+ }
+ continue;
+ }
+ } else if(lc == "\x00") {
+ continue;
+ }
+
if(lc == "\x02") {
emitEndToken();
}
emitEndToken();
-}
\ No newline at end of file
+}
+
+String.prototype.toHSBColour = function(client) {
+ var lower = client.toIRCLower(client.stripPrefix(this));
+ if(lower == client.lowerNickname)
+ return null;
+
+ var hash = 0;
+ for(var i=0;i<lower.length;i++)
+ hash = 31 * hash + lower.charCodeAt(i);
+
+ var hue = Math.abs(hash) % 360;
+
+ return new Color([hue, 70, 60], "hsb");
+}