acedece14 / Trovo mana

// ==UserScript==
// @name         Trovo mana
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Autocollect mana in live streams
// @author       acedece14 (vk.com/id6332939)
// @copyrignt    2022, acedece14 (https://openuserjs.org/users/acedece14)
// @match        https://trovo.live/s/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=trovo.live
// @grant        none
// @updateURL    https://openuserjs.org/meta/acedece14/Trovo_mana.meta.js
// @downloadURL  https://openuserjs.org/install/acedece14/Trovo_mana.user.js
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';
  // utility function
  function copyAttributes(source, target) {
    return Array.from(source.attributes).forEach(attribute => {
      target.setAttribute(
        attribute.nodeName === 'id' ? 'data-id' : attribute.nodeName,
        attribute.nodeValue,
      );
    });
  }
  var needUpdate = true;
  // create new button for mana collecting
  var newBtn = document.createElement('button');
  newBtn.classList.add('cast-btn');
  newBtn.onclick = function () {
    needUpdate = !needUpdate;
    if (needUpdate) {
      newBtn.innerText = 'Stop collect';
      newBtn.classList.add('active');
    }
    else {
      newBtn.innerText = 'Start collect';
      newBtn.classList.remove('active');
    }
  };

  setTimeout(function () {
    // hide crap on screen
    var badBtn = document.querySelector('.icon-zoom-out');
    if (badBtn != null) badBtn.click();
    // find cast button and append new button
    var castBtnParent = document.querySelector('.cast-btn');
    copyAttributes(castBtnParent, newBtn);
    castBtnParent.parentElement.appendChild(newBtn);
    newBtn.click();
  }, 5000);

  setInterval(function () {
    if (needUpdate == false) return;
    var btn = document.querySelector('.cast-btn');
    if (btn != null) {
      btn.click();
      btn.click();
    }
  }, 10000);
})();