Trovo: Mana harvester

Get trovo mana

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           Trovo: Mana harvester
// @name:ru        Trovo: автосборщик маны
// @description    Get trovo mana
// @description:ru Скрипт автоматического сбора маны
// @namespace      http://tampermonkey.net/
// @version        0.0.8
// @author         traceer, xleeuwx
// @match          https://trovo.live/*
// @grant          none
// @license        MIT
// @icon           https://www.google.com/s2/favicons?domain=trovo.live
// ==/UserScript==


(function () {
    'use strict';
    setTimeout(waitForInitialize, 30);
}());

function waitForInitialize() {
    if (typeof window !== 'undefined') {
        initialize();
    } else {
        setTimeout(waitForInitialize, 30);
    }
}

function initialize() {
    waitForFindButtonElement(0);
    console.log('Mana harvester is initialized');
}

function waitForFindButtonElement(waitLonger) {
    if (waitLonger == 1) {
        var RandRangeNum = Math.floor(Math.random() * (270 - 120) + 120);
    } else {
        var RandRangeNum = Math.floor(Math.random() * (90 - 15) + 15);
    };
    setTimeout(findButtonElement, (RandRangeNum * 1000) );
}

function findBoxElement() {

    // find opened the Cast Spell box
    var foundBox = document.querySelectorAll("article.gift-box");
    var foundBtn = document.querySelectorAll("button.spell-btn");
    var foundProgress = document.querySelectorAll("div.progress-bg")
    var waitLonger = 0;

    if(foundBox.length > 0) {
        console.log('Found the Cast Spell box, will close it');
        clickElement(foundBtn[0]);
    }

    if(foundProgress.length > 0 && foundProgress[0].style.cssText == 'transform: scaleX(1);') {
        var waitLonger = 1;
    } else {
        var waitLonger = 0;
    }

    // delete styles which hide the Cast Spell box
    const text = document.querySelectorAll('.giftbox-style');
    for (const el of text) {
       el.remove();
    }
    waitForFindButtonElement(waitLonger);
}

function findButtonElement() {

    // First find the chat element
    var foundButton = document.querySelectorAll("button.spell-btn");
    var foundGiftBox = document.querySelectorAll("article.gift-box");

    if(foundButton.length > 0 && foundGiftBox.length != 1) {
        console.log('Found the damm button, now click it');
        if(typeof foundButton[0] !== 'undefined') {
            clickElement(foundButton[0]);

            // add style for hide Cast Spell box
            var head = document.head || document.getElementsByTagName('head')[0];
            var style = document.createElement('style');
            var css = '.gift-box { display: none !important; }';
            style.type = 'text/css';
            style.classList.add("giftbox-style");
            style.appendChild(document.createTextNode(css));
            head.appendChild(style);
        }

        setTimeout(findBoxElement, 1000 );
    } else {
        setTimeout(waitForFindButtonElement, 1000 );
    }
}

function clickElement(buttonEl) {
    if(typeof buttonEl !== 'undefined' && buttonEl !== null) {
        try {
            buttonEl.click();
            console.log('i clicked it for you');
        } catch (e) {
            console.log('Cannot click the damm button, something whent wrong', e);
        }
    }
}