Pendoria - FixHazzy

Overwrites what Hazzy says in realtime with some nice sentences.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Pendoria - FixHazzy
// @description  Overwrites what Hazzy says in realtime with some nice sentences.
// @namespace    http://pendoria.net/
// @version      0.0.2
// @author       Xortrox
// @contributor  Tester: Hazzy
// @match        http://pendoria.net/game
// @match        https://pendoria.net/game
// @match        http://www.pendoria.net/game
// @match        https://www.pendoria.net/game
// @grant        none
// ==/UserScript==

inspirationalQuotes = [
'Xortrox made me the way I am! That\'s why I am soooo happy :D',
'Maria is love Maria is life', 
'Puls3 is a generous guy!', 
'It\'sa me Hazzio!',
'Me Hazzy! Me Happy!', 
'Flowers are pretty tbh, and you look like one my peoples :3!', 
'Hello sunshine! how is your day?', 
'My name is Hazzy, and I and very happy today :3'
];
 
function getChatMessageTimestamp(msg){
    return msg.substr(0, msg.indexOf(' '))
}
function fixhazzy(message, channel, username, id) {
    if (channel === '/main' || channel === 'hazzyfix') {
        // Hazy ID
        if (id === 1774) {
            console.log("IT WAS HAZZY!");
        }
 
        setTimeout(() => {
            let timestamp = getChatMessageTimestamp(message);
            let chatLine = $('li:contains("' + timestamp + '")');
 
            if(!chatLine) {
                return console.log('No chat line found.');
            }
 
            console.log('chatLine:', chatLine);
            let msgText = chatLine[0].innerHTML.substr(chatLine[0].innerHTML.indexOf('</a>: ') + 6)
            //console.log('text:', msgText);
            //console.log('New innerHTML with replaced text:', chatLine[0].innerHTML.replace(msgText, 'Flowers are pretty tbh, and you look like one my peoples :3!'));
            if (id === 1774) {
                let newInner = chatLine[0].innerHTML.replace(msgText, inspirationalQuotes[Math.floor(Math.random() * inspirationalQuotes.length)])
                chatLine[0].innerHTML = newInner;
                console.log('chat now:', chatLine[0].innerHTML);
            }
        }, 200);
        console.log('Received main message:', message, '\nusername:', username);
    }
}
socket.on('message', fixhazzy);
socket.io.on('message', fixhazzy);