Pendoria - FixHazzy

Overwrites what Hazzy says in realtime with some nice sentences.

As of 15. 08. 2018. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Pendoria - FixHazzy
// @description  Overwrites what Hazzy says in realtime with some nice sentences.
// @namespace    http://pendoria.net/
// @version      0.0.2
// @author       Anders Morgan Larsen (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);