Hyppy / AutoBallad

// ==UserScript==
// @name         AutoBallad
// @namespace    http://tampermonkey.net/
// @version      1.11
// @description  Automatically click some buttons in Ballad of Heroes
// @author       Hyppy
// @match        https://talaxi.github.io/balladofheroes/
// @match        http://talaxi.github.io/balladofheroes/
// @icon         https://talaxi.github.io/balladofheroes/favicon.ico
// @license      MIT
// @updateURL    https://openuserjs.org/src/scripts/Hyppy/AutoBallad.user.js
// @downloadURL  https://openuserjs.org/src/scripts/Hyppy/AutoBallad.user.js
// @homepage     https://openuserjs.org/scripts/Hyppy/AutoBallad
// @grant        none
// @run-at       document-end
// ==/UserScript==

// ==OpenUserJS==
// @author Hyppy
// ==/OpenUserJS==

/* jshint esversion: 6 */ 


(function() {
    'use strict';

    var duoInt = -1;
    var duoDiv = document.createElement('div');
    duoDiv.id = 'actionDivId';
    duoDiv.innerHTML = `<button data-autoduo id="duoButton" type="button" class="buttonStyled">AutoDuo OFF</button>`;
    document.getElementsByClassName("gameName")[0].insertAdjacentElement("afterend", duoDiv);

    function duoClicker() {
        var duoButtons = document.getElementsByClassName("duoAbilityImage");
        if (duoButtons.length > 0) {
            for (var i = 0; i < duoButtons.length; i++) {
                duoButtons[i].click();
            }
        }
    }

    document.getElementById("duoButton").onclick = function () {
        if (duoInt == -1) {
            duoInt = setInterval( duoClicker, 100);
            document.getElementById("duoButton").innerHTML = "AutoDuo ON";
        }
        else {
            clearInterval(duoInt);
            duoInt = -1;
            document.getElementById("duoButton").innerHTML = "AutoDuo OFF";
        }

    };


})();