/
Lichess_Chat_Enhancer.user.js
62 lines (56 loc) · 2.33 KB
/
Lichess_Chat_Enhancer.user.js
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
// ==UserScript==
// @id Lichess_Chat_Enhancer@https://github.com/mawekuwe/UserScripts
// @name Lichess Chat Enhancer
// @namespace https://github.com/mawekuwe/UserScripts
// @description Enhance the chat in Lichess.org
// @author mawekuwe
// @copyright 2015+, mawekuwe
// @license GNU GPLv3
// @homepage https://github.com/mawekuwe/UserScripts/tree/master/Lichess_Chat_Enhancer
// @homepageURL https://github.com/mawekuwe/UserScripts/tree/master/Lichess_Chat_Enhancer
// @downloadURL https://github.com/mawekuwe/UserScripts/raw/master/Lichess_Chat_Enhancer/Lichess_Chat_Enhancer.user.js
// @updateURL https://github.com/mawekuwe/UserScripts/raw/master/Lichess_Chat_Enhancer/Lichess_Chat_Enhancer.user.js
// @supportURL https://github.com/mawekuwe/UserScripts/issues
// @contributionURL
// @version 1.5
// @grant none
// @run-at document-end
// @include http://*.lichess.org/*
// @icon https://raw.githubusercontent.com/ornicar/lila/master/public/images/favicon-32-white.png
// ==/UserScript==
var $dark = $("body.dark");
if ($dark.length) {
var colors = [
"#2F5E8C", "#EF2F41", "#FFC700", "#61BDF2", "#5179D6", "#66CC66", "aqua", "lime", "silver", "teal", "navy", "white",
"fuchsia", "olive", "yellow", "gray", "purple", "green", "red"];
} else {
var colors = [
"#EF2F41", "#61BDF2", "#5179D6", "#66CC66", "black", "maroon", "teal", "blue", "navy","fuchsia", "olive", "gray",
"purple", "green", "red"];
}
var colorContents = {};
var colorize = function () {
$('div.messages_container ol.messages.content span a').each(function (i, e) {
var keyContent = $(e).text();
if (colorContents[keyContent] === undefined) colorContents[keyContent] = colors[i % colors.length];
$(e).css('color', colorContents[keyContent]);
});
};
colorize();
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
var list = document.querySelector('ol.messages');
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.type === 'childList') {
colorize();
}
});
});
var chat = $('#chat');
if (chat.length) {
observer.observe(list, {
attributes: true,
childList: true,
characterData: true
});
}