1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
"use strict";
var colorTableLight = [
// Tomorrow theme (light) (ish)
"#4d4d4c", // Foreground
"#c82829", // Red
"#cb6b01", // Orange (darker)
"#2d981a", // Green(ish)
"#3e999f", // Aqua
"#4271ae", // Blue
"#8959a8", // Purple
// Solarized theme
"#002b36", // Base03
"#586e75", // Base01
"#657b83", // Base00
"#839496", // Base0
"#b58900", // Yellow
"#cb4b16", // Orange
"#dc322f", // Red
"#d33682", // Magenta
"#6c71c4", // Violet
"#268bd2", // Blue
"#2aa198", // Cyan
"#859900", // Green
];
var colorTableDark = [
// Tomorrow theme (dark)
"#c5c8c6", // Foreground
"#969896", // Comment
"#cc6666", // Red
"#de935f", // Orange
"#f0c674", // Yellow
"#b5bd68", // Green
"#8abeb7", // Aqua
"#81a2be", // Blue
"#b294bb", // Purple
// Solarized theme
"#fdf6e3", // Base3
"#eee8d5", // Base2
"#93a1a1", // Base1
"#839496", // Base0
"#b58900", // Yellow
"#cb4b16", // Orange
"#dc322f", // Red
"#d33682", // Magenta
"#6c71c4", // Violet
"#268bd2", // Blue
"#2aa198", // Cyan
"#859900", // Green
];
// weechat's gui_nick_hash_djb2_32
function nickhash(nick) {
var h = 0;
for (var i = 0; i < nick.length; i++)
h ^= (h << 5) + (h >> 2) + nick.charCodeAt(i);
return h & 0x7fffffff;
}
function renderNickColors(dark) {
var table = dark ? colorTableDark : colorTableLight;
var n = table.length;
var spans = document.querySelectorAll("table#events span.nick");
for (var i = 0; i < spans.length; i++) {
var el = spans[i];
var text = el.innerText;
var h = nickhash(el.innerText);
el.setAttribute("style", "color: " + table[h % n]);
}
}
window.addEventListener("load", function() {
var querystr = "(prefers-color-scheme: dark)";
if (!("matchMedia" in window)) {
renderNickColors(false);
return;
}
var queryList = window.matchMedia(querystr);
renderNickColors(queryList.matches);
// Apparently older Safari doesn't have addEventListener here yet
if ("addEventListener" in queryList) {
queryList.addEventListener("change", function(ql) {
renderNickColors(ql.matches);
});
} else if ("addListener" in queryList) {
queryList.addListener(function() {
renderNickColors(window.matchMedia(querystr).matches);
});
}
});
|