Tùy chỉnh phòng chat NimoTV: thêm màu cho tên người dùng, nút trả lời, sửa lỗi từ bị chặn và lỗi trùng video.
当前为
// ==UserScript==
// @name NimoTV Chat Enhancer
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Tùy chỉnh phòng chat NimoTV: thêm màu cho tên người dùng, nút trả lời, sửa lỗi từ bị chặn và lỗi trùng video.
// @author You
// @match https://*.nimo.tv/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Hàm lấy cookie
function getCookie(name) {
return document.cookie.split('; ').reduce((r, v) => {
const parts = v.split('=');
return parts[0] === name ? decodeURIComponent(parts[1]) : r;
}, '');
}
// Hàm chuyển HEX sang HSL
function hexToHSL(H) {
let r = 0, g = 0, b = 0;
if (H.length == 4) {
r = '0x' + H[1] + H[1];
g = '0x' + H[2] + H[2];
b = '0x' + H[3] + H[3];
} else if (H.length == 7) {
r = '0x' + H[1] + H[2];
g = '0x' + H[3] + H[4];
b = '0x' + H[5] + H[6];
}
r /= 255;
g /= 255;
b /= 255;
let cmin = Math.min(r, g, b),
cmax = Math.max(r, g, b),
delta = cmax - cmin,
h = 0,
s = 0,
l = 0;
if (delta == 0) {
h = 0;
} else if (cmax == r) {
h = ((g - b) / delta) % 6;
} else if (cmax == g) {
h = (b - r) / delta + 2;
} else {
h = (r - g) / delta + 4;
}
h = Math.round(h * 60);
if (h < 0) {
h += 360;
}
l = (cmax + cmin) / 2;
s = delta == 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
s = +(s * 100).toFixed(1);
l = +(l * 100).toFixed(1);
return { h, s, l };
}
// Danh sách màu mặc định
const defaultColors = ['#ff0000', '#0000ff', '#008000', '#b22222', '#ff7f50', '#9acd32', '#ff4500', '#2e8b57', '#daa520', '#d2691e', '#5f9ea0', '#1e90ff', '#ff69b4', '#8a2be2', '#00ff7f'];
let users = {};
// Theo dõi thay đổi DOM
new MutationObserver((mutations, observer) => {
for (const mutation of mutations) {
if (mutation.type === 'childList') {
for (const node of mutation.addedNodes) {
// Tùy chỉnh tin nhắn chat
if (node && node.classList && node.classList.contains('nimo-room__chatroom__message-item')) {
const chatMessage = node;
const username = chatMessage.querySelector('.nm-message-nickname').innerHTML;
const currentUserName = getCookie('userName');
// Gán màu cho người dùng
if (!users[username]) {
const color = Math.random() < 0.5 ? defaultColors[Math.floor(13 * Math.random())] : '#' + Math.floor(16777215 * Math.random()).toString(16);
let { h, s } = hexToHSL(color);
users[username] = `hsl(${h}, ${s}%, 65%)`;
}
// Áp dụng màu
const colon = chatMessage.querySelector('.nimo-room__chatroom__message-item__info-colon');
if (colon) {
colon.style.color = users[username];
}
chatMessage.querySelector('.nm-message-nickname').style.color = users[username];
// Thêm nút trả lời
const btn = document.createElement('span');
btn.classList.add('reply-btn-chat');
btn.innerHTML = ' <img src="https://img.icons8.com/office/32/paper-plane.png" width="16" height="16" style="vertical-align:middle;"/>';
btn.addEventListener('click', () => {
const [chatbox] = document.getElementsByClassName('nimo-chat-box__input');
chatbox.value = `@${username} `;
chatbox.focus();
});
chatMessage.append(btn);
// Sửa lỗi từ bị chặn
if (currentUserName === username) {
const [chatbox] = document.getElementsByClassName('nimo-chat-box__input');
if (chatbox.value.length > 2) {
chatMessage.classList.add('message-filtered');
chatbox.parentElement.classList.add('message-filtered');
} else {
chatbox.parentElement.classList.remove('message-filtered');
}
}
}
// Sửa lỗi trùng video
if (node && node.nodeName && node.nodeName.toLowerCase() === 'video') {
const videoContainer = node.parentElement;
if (videoContainer && videoContainer.classList && videoContainer.classList.contains('video-player')) {
const videos = videoContainer.querySelectorAll('video');
if (videos && videos.length > 1) {
videos[0].remove();
}
}
}
}
}
}
}).observe(document.body, {
attributes: false,
childList: true,
subtree: true
});
})();