Untitled diff
563 linee
// ==UserScript==
// ==UserScript==
// @name        Reloader
// @name        Reloader
// @namespace   HVRLD3
// @namespace   HVRLD3
// @author      nihilvoid, Dan31, FabulousCupcake
// @author      nihilvoid, Dan31, FabulousCupcake
// @run-at      document-end
// @run-at      document-end
// @include     http://hentaiverse.org/*
// @include     http://hentaiverse.org/*
// @version     1.3.1
// @version     1.3.1a
// @grant       none
// @grant       none
// ==/UserScript==
// ==/UserScript==
// Vanilla Reloader:
// Vanilla Reloader:
// http://forums.e-hentai.org/index.php?s=&showtopic=65126&view=findpost&p=4259841
// http://forums.e-hentai.org/index.php?s=&showtopic=65126&view=findpost&p=4259841
// Select a custom font in your settings:
// Select a custom font in your settings:
// http://hentaiverse.org/?s=Character&ss=se
// http://hentaiverse.org/?s=Character&ss=se
// Todo List:
// Todo List:
// - fix battlelog append
// - fix battlelog append
// - add Hoheneim's additions
// - add Hoheneim's additions
// - fix round counter display at end of battle serie
// - fix round counter display at end of battle serie
// - add support for browsers other than Firefox (-> update mousemelee)
// - add support for browsers other than Firefox (-> update mousemelee)
// Credits and Sources
// Credits and Sources
// ------------------------
// ------------------------
// Original reloader idea   : nihilvoid
// Original reloader idea   : nihilvoid
// Reloader maintainer      : Dan31
// Reloader maintainer      : Dan31
// No Blinking  : HV Stat
// No Blinking  : HV Stat
/* ======================================== *\
/* ======================================== *\
 * ============= CONFIGURATION ============ *
 * ============= CONFIGURATION ============ *
\* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
\* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
var settings = {
var settings = {
    hideWelcome: true,          // Hide the "Welcome to the Hentaiverse" image/logo
    hideWelcome: true,          // Hide the "Welcome to the Hentaiverse" image/logo
    noBlinking: true,           // Disable buff/debuff blinking
    noBlinking: true,           // Disable buff/debuff blinking
    effectDurations: true,      // Show buff/debuff durations
    effectDurations: true,      // Show buff/debuff durations
    gemIcon: true,              // Show gem/powerup, click on icon to use
    gemIcon: true,              // Show gem/powerup, click on icon to use
    roundCounter: true,         // Show current round and rounds remaining
    roundCounter: true,         // Show current round and rounds remaining
    defaultAction: 0,           // Change the default action to a T1 spell
    defaultAction: 0,           // Change the default action to a T1 spell
    // |     0     |      1      |   2    |     3      |  4   |   5   |     6      |
    // |     0     |      1      |   2    |     3      |  4   |   5   |     6      |
    // | No Change | Fiery Blast | Freeze | Shockblast | Gale | Smite | Corruption |
    // | No Change | Fiery Blast | Freeze | Shockblast | Gale | Smite | Corruption |
    mouseMelee: true,           // MouseMelee ( hover on enemies to attack )
    mouseMelee: true,           // MouseMelee ( hover on enemies to attack )
    minHP: 0.4,                 // Stop if hp is below this threshold
    minHP: 0.4,                 // Stop if hp is below this threshold
    minMP: 0.12,                // Stop if mp ...
    minMP: 0.12,                // Stop if mp ...
    minSP: 0.3,                 // Stop if sp ...
    minSP: 0.3,                 // Stop if sp ...
    stopWhenChanneling: true,   // Stop if you have channeling buff
    stopWhenChanneling: true,   // Stop if you have channeling buff
    battleLog: true,            // Show battle log
    battleLog: true,            // Show battle log
    //battleLogAppend: false,   //disabled for now (need to redo this without jQuery)
    //battleLogAppend: false,   //disabled for now (need to redo this without jQuery)
    skipToNextRound: true,      // Auto-advance to next round
    skipToNextRound: true,      // Auto-advance to next round
    popupTime: 0,               // after `popupTime`ms
    popupTime: 0,               // after `popupTime`ms
    showPopup: false,           // Show that end of round popup?
    showPopup: false,           // Show that end of round popup?
    counterPlus: true           // HV-Counter-Plus ( shows turns, speed, time, exp, and credits at the end of game )
    counterPlus: true           // HV-Counter-Plus ( shows turns, speed, time, exp, and credits at the end of game )
};
};
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *\
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *\
 * =========== CONFIGURATION END ========== *
 * =========== CONFIGURATION END ========== *
\* ======================================== */
\* ======================================== */
/* ======================================== *\
/* ======================================== *\
 * ============= INITIAL LOAD ============= *
 * ============= INITIAL LOAD ============= *
\* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
\* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
// Stuffs to be ran on page load
// Stuffs to be ran on page load
function initialPageLoad() {
function initialPageLoad() {
    // Hoverplay fix for Chrome
    // Hoverplay fix for Chrome
    // Constantly track cursor position to allow chrome to keep hitting a monster when hovering on one.
    // Constantly track cursor position to allow chrome to keep hitting a monster when hovering on one.
    // You'd have to keep moving your cursor without this fix
    // You'd have to keep moving your cursor without this fix
    if ( settings.mouseMelee ) {
    if ( settings.mouseMelee ) {
        // Get cursor position from the last round
        // Get cursor position from the last round
        curX = localStorage.getItem('curX');
        curX = localStorage.getItem('curX');
        curY = localStorage.getItem('curY');
        curY = localStorage.getItem('curY');
        localStorage.removeItem('curX');
        localStorage.removeItem('curX');
        localStorage.removeItem('curY');
        localStorage.removeItem('curY');
        // Update curX and curY whenever cursor moves
        // Update curX and curY whenever cursor moves
        if (window.Event) document.captureEvents(Event.MOUSEMOVE);
        if (window.Event) document.captureEvents(Event.MOUSEMOVE);
        document.onmousemove = function(e) {
        document.onmousemove = function(e) {
            curX = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
            curX = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
            curY = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
            curY = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
        };
        };
    }
    }
    // Change page title to "HV"
    // Change page title to "HV"
    document.title = 'HV';
    document.title = 'HV';
    // Insert stylesheet for Round Counter and Effect Duration
    // Insert stylesheet for Round Counter and Effect Duration
    var sheet = document.createElement('style');
    var sheet = document.createElement('style');
    sheet.innerHTML = '#round{position:absolute;left:1080px;top:15px;width:120px;font-size:20px;font-weight:bold;z-index:10;text-align:right}.duration{width:30px;display:inline-block;text-align:center;position:relative;margin-left:-30px;top:-4px}.duration>div{background:white;border:1px solid black;padding:0 2px;display:inline-block;min-width:8px;font-weight:bold;height:13px}';
    sheet.innerHTML = '#round{position:absolute;left:1080px;top:15px;width:120px;font-size:20px;font-weight:bold;z-index:10;text-align:right}.duration{width:30px;display:inline-block;text-align:center;position:relative;margin-left:-30px;top:-4px}.duration>div{background:white;border:1px solid black;padding:0 2px;display:inline-block;min-width:8px;font-weight:bold;height:13px}';
    // Hide Battle Log
    // Hide Battle Log
    if (!settings.battleLog) sheet.innerHTML += '#togpane_log {display: none}';
    if (!settings.battleLog) sheet.innerHTML += '#togpane_log {display: none}';
    // Hide Welcome Logo
    // Hide Welcome Logo
    if (settings.hideWelcome) { sheet.innerHTML += 'img.cw{display: none}.cbl:nth-of-type(1){padding-top:114px}'; }
    if (settings.hideWelcome) { sheet.innerHTML += 'img.cw{display: none}.cbl:nth-of-type(1){padding-top:114px}'; }
    document.head.appendChild(sheet);
    document.head.appendChild(sheet);
    /* ============== NO BLINKING ============= */
    /* ============== NO BLINKING ============= */
    if (settings.noBlinking) {
    if (settings.noBlinking) {
        window.addEventListener('beforescriptexecute', function(e) {
        window.addEventListener('beforescriptexecute', function(e) {
            if (/battle\.set_infopane\("Battle Time"\)/.test(e.target.innerHTML)) {
            if (/battle\.set_infopane\("Battle Time"\)/.test(e.target.innerHTML)) {
                e.preventDefault();
                e.preventDefault();
                window.removeEventListener(e.type, arguments.callee, true);
                window.removeEventListener(e.type, arguments.callee, true);
            }
            }
        }, true);
        }, true);
    }
    }
    /* ============ NO BLINKING END =========== */
    /* ============ NO BLINKING END =========== */
    /* ============= ROUND COUNTER ============ */
    /* ============= ROUND COUNTER ============ */
    if (settings.roundCounter) {
    if (settings.roundCounter) {
        var logs = document.querySelector('#togpane_log tr:nth-last-child(2)').textContent;
        var logs = document.querySelector('#togpane_log tr:nth-last-child(2)').textContent;
        if (/Round/.test(logs) && !sessionStorage.rounds) {
        if (/Round/.test(logs) && !sessionStorage.rounds) {
            var round = logs.match(/Round ([\d\s\/]+)/)[1];
            var round = logs.match(/Round ([\d\s\/]+)/)[1];
            sessionStorage.setItem('rounds', round);
            sessionStorage.setItem('rounds', round);
        } else {
        } else {
            var round = sessionStorage.getItem('rounds') || undefined;
            var round = sessionStorage.getItem('rounds') || undefined;
        }
        }
        if (round !== undefined) {
        if (round !== undefined) {
            var x = document.getElementById('mainpane').appendChild(document.createElement('div'));
            var x = document.getElementById('mainpane').appendChild(document.createElement('div'));
            x.id = 'round';
            x.id = 'round';
            x.innerHTML = round;
            x.innerHTML = round;
            var final = round.split('/');
            var final = round.split('/');
            switch (final[1] - final[0]) {
            switch (final[1] - final[0]) {
                case 0:
                case 0:
                    x.style.color = '#ff0000';
                    x.style.color = '#ff0000';
                    break;
                    break;
                case 1:
                case 1:
                    x.style.color = '#ffcc99';
                    x.style.color = '#ffcc99';
                    break;
                    break;
            }
            }
        }
        }
    }
    }
    /* =========== ROUND COUNTER END ========== */
    /* =========== ROUND COUNTER END ========== */
}
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *\
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *\
 * =========== INITIAL LOAD END =========== *
 * =========== INITIAL LOAD END =========== *
\* ======================================== */
\* ======================================== */
/* ======================================== *\
/* ======================================== *\
 * ============ ON PAGE RELOAD ============ *
 * ============ ON PAGE RELOAD ============ *
\* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
\* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
// Stuffs to be executed after the xhr request is sent
// Stuffs to be executed after the xhr request is sent
// and the page is loaded with new content.
// and the page is loaded with new content.
function OnPageReload() {
function OnPageReload() {
    // Reinitialize the battle manager
    // Reinitialize the battle manager
    window.battle = new window.Battle();
    window.battle = new window.Battle();
    window.battle.clear_infopane();
    window.battle.clear_infopane();
    // TODO: Anything that needs to trigger when a new battle page starts should go here
    // TODO: Anything that needs to trigger when a new battle page starts should go here
    //  i.e. Stat tracking, log parsing, battle-UI changes, etc.
    //  i.e. Stat tracking, log parsing, battle-UI changes, etc.
    /* ============ DEFAULT ACTION ============ */
    /* ============ DEFAULT ACTION ============ */
    function changeDefault(id) {
    function changeDefault(id) {
        var caller = document.getElementById(id.toString());
        var caller = document.getElementById(id.toString());
        window.battle.lock_action(caller, 1, 'magic', id);
        window.battle.lock_action(caller, 1, 'magic', id);
        window.battle.set_hostile_subattack(id);
        window.battle.set_hostile_subattack(id);
    }
    }
    switch (settings.defaultAction) {
    switch (settings.defaultAction) {
        //Default (Attack)
        //Default (Attack)
        case 0:
        case 0:
            break;
            break;
        case 1:
        case 1:
            //Fiery Blast
            //Fiery Blast
            changeDefault(111);
            changeDefault(111);
            break;
            break;
        case 2:
        case 2:
            //Freeze
            //Freeze
            changeDefault(121);
            changeDefault(121);
            break;
            break;
        case 3:
        case 3:
            //Shockblast
            //Shockblast
            changeDefault(131);
            changeDefault(131);
            break;
            break;
        case 4:
        case 4:
            //Gale
            //Gale
            changeDefault(141);
            changeDefault(141);
            break;
            break;
        case 5:
        case 5:
            //Smite
            //Smite
            changeDefault(151);
            changeDefault(151);
            break;
            break;
        case 6:
        case 6:
            //Corruption
            //Corruption
            changeDefault(161);
            changeDefault(161);
            break;
            break;
    }
    }
    /* ========== DEFAULT ACTION END ========== */
    /* ========== DEFAULT ACTION END ========== */
    /* ============ HV COUNTER PLUS =========== */
    /* ============ HV COUNTER PLUS =========== */
    if (settings.counterPlus) {
    if (settings.counterPlus) {
        (function(){
        (function(){
        var record = localStorage.record ? JSON.parse(localStorage.record) : {
        var record = localStorage.record ? JSON.parse(localStorage.record) : {
                'turns': 0,
                'turns': 0,
                'time': 0,
                'time': 0,
                'EXP': 0,
                'EXP': 0,
                'Credits': 0
                'Credits': 0
            },
            },
            pop = document.getElementsByClassName('btcp')[0],
            pop = document.getElementsByClassName('btcp')[0],
            set = function() {
            set = function() {
                localStorage.setItem('record', JSON.stringify(record));
                localStorage.setItem('record', JSON.stringify(record));
            },
            },
            build = function(item, point) {
            build = function(item, point) {
                record[item] = record[item] * 1 + point * 1;
                record[item] = record[item] * 1 + point * 1;
            };
            };
        if (!record.time) {
        if (!record.time) {
            build('time', Date.now());
            build('time', Date.now());
            set();
            set();
        }
        }
        if (pop) {
        if (pop) {
            var target, label, i = 0,
            var target, label, i = 0,
                textC = document.querySelectorAll('#togpane_log .t3b'),
                textC = document.querySelectorAll('#togpane_log .t3b'),
                turn = document.querySelector('#togpane_log .t1').textContent;
                turn = document.querySelector('#togpane_log .t1').textContent;
            build('turns', turn);
            build('turns', turn);
            while (i < textC.length) {
            while (i < textC.length) {
                target = textC[i].textContent;
                target = textC[i].textContent;
                if (/Victorious.$|Fleeing.$/.test(target)) break;
                if (/Victorious.$|Fleeing.$/.test(target)) break;
                label = target.match(/(\d+) ([EC]\w+).$/);
                label = target.match(/(\d+) ([EC]\w+).$/);
                if (label) build(label[2], label[1]);
                if (label) build(label[2], label[1]);
                i++;
                i++;
            }
            }
            if (pop.getElementsByTagName('img')[0]) set();
            if (pop.getElementsByTagName('img')[0]) set();
            else {
            else {
                var num = 0,
                var num = 0,
                    runTime = Math.floor((Date.now() - record.time) / 1000),
                    runTime = Math.floor((Date.now() - record.time) / 1000),
                    text = pop.getElementsByClassName('fd4'),
                    text = pop.getElementsByClassName('fd4'),
                    len = text.length,
                    len = text.length,
                    result = pop.appendChild(document.createElement('div'));
                    result = pop.appendChild(document.createElement('div'));
                result.style.cssText = 'font-size:15px;font-weight:bold;margin-top:15px;';
                result.style.cssText = 'font-size:15px;font-weight:bold;margin-top:15px;';
                for (i = 0; i < len; i++) text[i].firstChild.style.marginTop = '-4px';
                for (i = 0; i < len; i++) text[i].firstChild.style.marginTop = '-4px';
                pop.style.top = '23px';
                pop.style.top = '23px';
                if (len > 2) pop.style.height = len > 3 ? '190px' : '170px';
                if (len > 2) pop.style.height = len > 3 ? '190px' : '170px';
                for (var key in record) {
                for (var key in record) {
                    var div = result.appendChild(document.createElement('div'));
                    var div = result.appendChild(document.createElement('div'));
                    div.style.cssText = 'display:inline-block;margin-bottom:7px;';
                    div.style.cssText = 'display:inline-block;margin-bottom:7px;';
                    if (!(num % 2)) div.style.marginRight = '20px';
                    if (!(num % 2)) div.style.marginRight = '20px';
                    if (key == 'time') {
                    if (key == 'time') {
                        var hour = ('0' + Math.floor(runTime / 3600) % 100).slice(-2),
                        var hour = ('0' + Math.floor(runTime / 3600) % 100).slice(-2),
                            min = ('0' + Math.floor(runTime / 60) % 60).slice(-2),
                            min = ('0' + Math.floor(runTime / 60) % 60).slice(-2),
                            sec = ('0' + runTime % 60).slice(-2);
                            sec = ('0' + runTime % 60).slice(-2);
                        div.textContent = (hour !== 0 ? hour + ' h ' : '') + (min !== 0 ? min + ' m ' : '') + sec + ' s';
                        div.textContent = (hour !== 0 ? hour + ' h ' : '') + (min !== 0 ? min + ' m ' : '') + sec + ' s';
                        result.appendChild(document.createElement('br'));
                        result.appendChild(document.createElement('br'));
                    } else {
                    } else {
                        var total = record[key] + '';
                        var total = record[key] + '';
                        while (total != (total = total.replace(/^(\d+)(\d{3})/, '$1,$2')));
                        while (total != (total = total.replace(/^(\d+)(\d{3})/, '$1,$2')));
                        div.textContent = total + ' ' + key.toLowerCase();
                        div.textContent = total + ' ' + key.toLowerCase();
                        if (!num) div.textContent += ' (' + ((Math.floor((record[key] / runTime) * 1000)) / 1000).toFixed(2) + ' t/s)';
                        if (!num) div.textContent += ' (' + ((Math.floor((record[key] / runTime) * 1000)) / 1000).toFixed(2) + ' t/s)';
                    }
                    }
                    num++;
                    num++;
                }
                }
            }
            }
        }
        }
        })();
        })();
    }
    }
    /* ========== HV COUNTER PLUS END ========= */
    /* ========== HV COUNTER PLUS END ========= */
    /* ============= BUFF DURATION ============ */
    /* ============= BUFF DURATION ============ */
    if (settings.effectDurations) {
    if (settings.effectDurations) {
        (function(){
        (function(){
        var targets = document.querySelectorAll('img[onmouseover^="battle.set_infopane_effect"]'),
        var targets = document.querySelectorAll('img[onmouseover^="battle.set_infopane_effect"]'),
            i = targets.length;
            i = targets.length;
        while (i--) {
        while (i--) {
            var duration = targets[i].getAttribute('onmouseover').match(/, ([-\d]+)\)/);
            var duration = targets[i].getAttribute('onmouseover').match(/, ([-\d]+)\)/);
            if (!duration || duration < 0) duration = '-';
            if (!duration || duration < 0) duration = '-';
            else duration = duration[1];
            else duration = duration[1];
            var div = targets[i].parentNode.insertBefore(document.createElement('div'), targets[i].nextSibling);
            var div = targets[i].parentNode.insertBefore(document.createElement('div'), targets[i].nextSibling);
            div.appendChild(document.createElement('div')).innerHTML = duration;
            div.appendChild(document.createElement('div')).innerHTML = duration;
            div.className = 'duration';
            div.className = 'duration';
        }
        }
        })();
        })();
    }
    }
    /* =========== BUFF DURATION END ========== */
    /* =========== BUFF DURATION END ========== */
    /* =============== SHOW GEMS ============== */
    /* =============== SHOW GEMS ============== */
    if (settings.gemIcon) {
    if (settings.gemIcon) {
        (function(){
        (function(){
        var gem = document.getElementById('ikey_p');
        var gem = document.getElementById('ikey_p');
        var gem_icon = document.getElementById("gem_icon");
        var gem_icon = document.getElementById("gem_icon");
        if (gem && !gem_icon) {
        if (gem && !gem_icon) {
            var icon;
            var icon;
            switch (gem.getAttribute('onmouseover').match(/'([^\s]+) Gem/)[1]) {
            switch (gem.getAttribute('onmouseover').match(/'([^\s]+) Gem/)[1]) {
                case 'Mystic':
                case 'Mystic':
                    icon = 'channeling.png';
                    icon = 'channeling.png';
                    break;
                    break;
                case 'Health':
                case 'Health':
                    icon = 'healthpot.png';
                    icon = 'healthpot.png';
                    break;
                    break;
                case 'Mana':
                case 'Mana':
                    icon = 'manapot.png';
                    icon = 'manapot.png';
                    break;
                    break;
                case 'Spirit':
                case 'Spirit':
                    icon = 'spiritpot.png';
                    icon = 'spiritpot.png';
                    break;
                    break;
            }
            }
            gem_icon = document.querySelector('.btp').appendChild(document.createElement('img'));
            gem_icon = document.querySelector('.btp').appendChild(document.createElement('img'));
            //gem_icon.src = 'https://raw.github.com/greentea039/HVSTAT/5a7a1e09b8847394faacf0d4b1321d51cb96816f/css/images/' + icon;
            //gem_icon.src = 'https://raw.github.com/greentea039/HVSTAT/5a7a1e09b8847394faacf0d4b1321d51cb96816f/css/images/' + icon;
            //gem_icon.src = icon;
            //gem_icon.src = icon;
            gem_icon.src = 'http://ehgt.org/v/e/' + icon;
            gem_icon.src = 'http://ehgt.org/v/e/' + icon;
            gem_icon.style.cssText = 'border: 1px solid black; position: absolute; float: right; right: 6px; top: 8px;';
            gem_icon.style.cssText = 'border: 1px solid black; position: absolute; float: right; right: 6px; top: 8px;';
            gem_icon.onclick = function() {
            gem_icon.onclick = function() {
                window.battle.lock_action(gem, 1, 'items', 'ikey_p');
                window.battle.lock_action(gem, 1, 'items', 'ikey_p');
                window.battle.set_friendly_subattack('999');
                window.battle.set_friendly_subattack('999');
                window.battle.touch_and_go();
                window.battle.touch_and_go();
                gem.remove();
                gem.remove();
                gem_icon.remove();
                gem_icon.remove();
            };
            };
            gem_icon.id = "gem_icon";
            gem_icon.id = "gem_icon";
        } else if (!gem && gem_icon) {
        } else if (!gem && gem_icon) {
            gem_icon.remove();
            gem_icon.remove();
        }
        }
        })();
        })();
    }
    }
    /* ============= SHOW GEMS END ============ */
    /* ============= SHOW GEMS END ============ */
    /* ============== MOUSE MELEE ============= */
    /* ============== MOUSE MELEE ============= */
    if (settings.mouseMelee) {
    if (settings.mouseMelee) {
        (function(){
        (function(){
        function getMonsterUnderCursor() {
        function getMonsterUnderCursor() {
            var el = document.elementFromPoint(curX, curY);
            var el = document.elementFromPoint(curX, curY);
            var result = false;
            var result = false;
            // Check `el` and iteratively its parents until we hit body or found monster
            // Check `el` and iteratively its parents until we hit body or found monster
            while(!result) {
            while(!result) {
                if(el.nodeName.toLowerCase() === 'body') break;
                if(el.nodeName.toLowerCase() === 'body') break;
                result = ( el.id.match('mkey') ? el : false );
                result = ( el.id.match('mkey') ? el : false );
                el = el.parentElement;
                el = el.parentElement;
            }
            }
            return result;
            return result;
        }
        }
        function NoHoverClick() {
        function NoHoverClick() {
            var bars = document.getElementsByClassName("cwb2");
            var bars = document.getElementsByClassName("cwb2");
            var hp = bars[0].width / 120;
            var hp = bars[0].width / 120;
            var mp = bars[1].width / 120;
            var mp = bars[1].width / 120;
            var sp = bars[2].width / 120;
            var sp = bars[2].width / 120;
            //var oc = bars[3].width/120;
            //var oc = bars[3].width/120;
            var low_hp = (hp < settings.minHP);
            var low_hp = (hp < settings.minHP);
            var low_mp = (mp < settings.minMP);
            var low_mp = (mp < settings.minMP);
            var low_sp = (sp < settings.minSP);
            var low_sp = (sp < settings.minSP);
            //var oc_full = (oc == 1);
            //var oc_full = (oc == 1);
            var bar_backs = document.getElementsByClassName("cwbdv");
            var bar_backs = document.getElementsByClassName("cwbdv");
            if (low_hp) bar_backs[0].setAttribute("style", "background-color:purple");
            if (low_hp) bar_backs[0].setAttribute("style", "background-color:purple");
            if (low_mp) bar_backs[1].setAttribute("style", "background-color:purple");
            if (low_mp) bar_backs[1].setAttribute("style", "background-color:purple");
            if (low_sp) bar_backs[2].setAttribute("style", "background-color:purple");
            if (low_sp) bar_backs[2].setAttribute("style", "background-color:purple");
            var is_channeling = function() {
            var is_channeling = function() {
                if (!settings.stopWhenChanneling) return false;
                if (!settings.stopWhenChanneling) return false;
                var status_icons = document.querySelectorAll('img[onmouseover^="battle.set_infopane_effect"]');
                var status_icons = document.querySelectorAll('img[onmouseover^="battle.set_infopane_effect"]');
                for (var i = 0, len = status_icons.length; i < len; i++) {
                for (var i = 0, len = status_icons.length; i < len; i++) {
                    if (/\bchanneling\b/i.test(status_icons[i].onmouseover.toString())) {
                    if (/\bchanneling\b/i.test(status_icons[i].onmouseover.toString())) {
                        //var img = document.querySelector('.btp').appendChild(document.createElement('img'));
                        //var img = document.querySelector('.btp').appendChild(document.createElement('img'));
                        //img.src = "http://ehgt.org/v/e/channeling.png";
                        //img.src = "http://ehgt.org/v/e/channeling.png";
                        //img.style.cssText = 'border: 3px solid cyan; margin-right:2px; margin-left:2px;';
                        //img.style.cssText = 'border: 3px solid cyan; margin-right:2px; margin-left:2px;';
                        return true;
                        return true;
                    }
                    }
                }
                }
                return false;
                return false;
            };
            };
            //return (low_hp || low_mp || low_sp || oc_full || is_channeling);
            //return (low_hp || low_mp || low_sp || oc_full || is_channeling);
            return (low_hp || low_mp || low_sp || is_channeling());
            return (low_hp || low_mp || low_sp || is_channeling());
        }
        }
        var mpane = document.getElementById('monsterpane');
        var mpane = document.getElementById('monsterpane');
        if (mpane && !NoHoverClick()) {
        if (mpane && !NoHoverClick()) {
            // Check if cursor is hovering on a monster
            // Check if cursor is hovering on a monster
            var monster = getMonsterUnderCursor();
            var monster = getMonsterUnderCursor();
            if ( monster ) {
            if ( monster && monster.onclick !== null ) {
                monster.click();
                monster.click();
            } else {
            } else {
                // Add hover event listeners
                // Add hover event listeners
                var m = mpane.getElementsByClassName("btm1");
                var m = mpane.getElementsByClassName("btm1");
                for (var i = 0; i < m.length; i++) {
                for (var i = 0; i < m.length; i++) {
                    if (m[i].hasAttribute('onclick')) {
                    if (m[i].hasAttribute('onclick')) {
                        m[i].setAttribute('onmouseover', m[i].getAttribute('onclick'));
                        m[i].setAttribute('onmouseover', m[i].getAttribute('onclick'));
                    }
                    }
                }
                }
            }
            }
        }
        }
    })();
    })();
    }
    }
    /* ============ MOUSE MELEE END =========== */
    /* ============ MOUSE MELEE END =========== */
}
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *\
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *\
 * ========== ON PAGE RELOAD END ========== *
 * ========== ON PAGE RELOAD END ========== *
\* ======================================== */
\* ======================================== */
/* ======================================== *\
/* ======================================== *\
 * ===============  C O R E  ============== *
 * ===============  C O R E  ============== *
\* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
\* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* ============= SUBMIT ACTION ============ */
/* ============= SUBMIT ACTION ============ */
function SubmitAction() {
function SubmitAction() {
    // End of round, continue button pressed
    // End of round, continue button pressed
    if (document.getElementById("battleaction").value === 0) {
    if (document.getElementById("battleaction").value === 0) {
        window.location.href = window.location.href;
        window.location.href = window.location.href;
        return;
        return;
    }
    }
    //var loadStart = (new Date()).getTime();
    //var loadStart = (new Date()).getTime();
    // Serialize the form data
    // Serialize the form data
    var inputs = document.getElementsByTagName("input");
    var inputs = document.getElementsByTagName("input");
    var serializedForm = "";
    var serializedForm = "";
    for (var i = 0; i < inputs.length; i++) {
    for (var i = 0; i < inputs.length; i++) {
        if (i !== 0)
        if (i !== 0)
            serializedForm += "&";
            serializedForm += "&";
        serializedForm += inputs[i].id + "=" + inputs[i].value;
        serializedForm += inputs[i].id + "=" + inputs[i].value;
    }
    }
    // Send the AJAX call
    // Send the AJAX call
    var r = new XMLHttpRequest();
    var r = new XMLHttpRequest();
    r.open("POST", "", true);
    r.open("POST", "", true);
    r.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
    r.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
    r.responseType = 'document';
    r.responseType = 'document';
    r.onload = function() {
    r.onload = function() {
        if (r.status >= 200 && r.status < 400) {
        if (r.status >= 200 && r.status < 400) {
            updatePage(r.response);
            updatePage(r.response);
        }
        }
    };
    };
    r.send(serializedForm);
    r.send(serializedForm);
    /* ============== UPDATE PAGE ============= */
    /* ============== UPDATE PAGE ============= */
    function updatePage(data) {
    function updatePage(data) {
        var existing, newStuff, i;
        var existing, newStuff, i;
        var replacements = '.cwbdv, .bte, #ckey_spirit, #ckey_defend, #togpane_magico, #togpane_magict, #togpane_item, #quickbar, #togpane_log';
        var replacements = '.cwbdv, .bte, #ckey_spirit, #ckey_defend, #togpane_magico, #togpane_magict, #togpane_item, #quickbar, #togpane_log';
var monsterReplacements = '#mkey_0, #mkey_1, #mkey_2, #mkey_3, #mkey_4, #mkey_5, #mkey_6, #mkey_7, #mkey_8, #mkey_9';
var monsterReplacements = '#mkey_0, #mkey_1, #mkey_2, #mkey_3, #mkey_4, #mkey_5, #mkey_6, #mkey_7, #mkey_8, #mkey_9';
        //var loadEnd = (new Date()).getTime();
        //var loadEnd = (new Date()).getTime();
        //console.log("PostTime = " + (loadEnd - loadStart));
        //console.log("PostTime = " + (loadEnd - loadStart));
        // Handle simple replacements
        // Handle simple replacements
        existing = document.querySelectorAll(replacements);
        existing = document.querySelectorAll(replacements);
        newStuff = data.querySelectorAll(replacements);
        newStuff = data.querySelectorAll(replacements);
        i = existing.length;
        i = existing.length;
        while (i--) {
        while (i--) {
            existing[i].parentNode.replaceChild(newStuff[i], existing[i]);
            existing[i].parentNode.replaceChild(newStuff[i], existing[i]);
        }
        }
        // Handle monster replacements (don't replace dead monsters)
        // Handle monster replacements (don't replace dead monsters)
        existing = document.querySelectorAll(monsterReplacements);
        existing = document.querySelectorAll(monsterReplacements);
        newStuff = data.querySelectorAll(monsterReplacements);
        newStuff = data.querySelectorAll(monsterReplacements);
        i = existing.length;
        i = existing.length;
        while (i--) {
        while (i--) {
            if (existing[i].hasAttribute("onclick") || newStuff[i].hasAttribute("onclick")) {
            if (existing[i].hasAttribute("onclick") || newStuff[i].hasAttribute("onclick")) {
                existing[i].parentNode.replaceChild(newStuff[i], existing[i]);
                existing[i].parentNode.replaceChild(newStuff[i], existing[i]);
            }
            }
        }
        }
        var popup = data.getElementsByClassName('btcp');
        var popup = data.getElementsByClassName('btcp');
        var navbar = data.getElementById('navbar');
        var navbar = data.getElementById('navbar');
        // Navbar
        // Navbar
        if (navbar) {
        if (navbar) {
            // Show navbar
            // Show navbar
            var mainpane = document.getElementById('mainpane');
            var mainpane = document.getElementById('mainpane');
            mainpane.parentNode.insertBefore(navbar, mainpane);
            mainpane.parentNode.insertBefore(navbar, mainpane);
            window.at_attach("parent_Character", "child_Character", "hover", "y", "pointer");
            window.at_attach("parent_Character", "child_Character", "hover", "y", "pointer");
            window.at_attach("parent_Bazaar", "child_Bazaar", "hover", "y", "pointer");
            window.at_attach("parent_Bazaar", "child_Bazaar", "hover", "y", "pointer");
            window.at_attach("parent_Battle", "child_Battle", "hover", "y", "pointer");
            window.at_attach("parent_Battle", "child_Battle", "hover", "y", "pointer");
            window.at_attach("parent_Forge", "child_Forge", "hover", "y", "pointer");
            window.at_attach("parent_Forge", "child_Forge", "hover", "y", "pointer");
        }
        }
        // Popup
        // Popup
        if (popup.length !== 0) {
        if (popup.length !== 0) {
            if (!navbar) {
            if (!navbar) {
                //End of round
                //End of round
                if (settings.showPopup) {
                if (settings.showPopup) {
                    //Show popup
                    //Show popup
                    var parent = document.getElementsByClassName('btt')[0];
                    var parent = document.getElementsByClassName('btt')[0];
                    parent.insertBefore(popup[0], parent.firstChild);
                    parent.insertBefore(popup[0], parent.firstChild);
                }
                }
            } else {
            } else {
                //End of battle serie
                //End of battle serie
                //Show popup
                //Show popup
                var parent = document.getElementsByClassName('btt')[0];
                var parent = document.getElementsByClassName('btt')[0];
                parent.insertBefore(popup[0], parent.firstChild);
                parent.insertBefore(popup[0], parent.firstChild);
            }
            }
        }
        }
        //var swapEnd = (new Date()).getTime();
        //var swapEnd = (new Date()).getTime();
        //console.log("SwapTime = " + (swapEnd - loadEnd));
        //console.log("SwapTime = " + (swapEnd - loadEnd));
        // Run all script modules again; new content has been loaded
        // Run all script modules again; new content has been loaded
        OnPageReload();
        OnPageReload();
        if ((popup.length !== 0) || navbar) {
        if ((popup.length !== 0) || navbar) {
            //Reset the round counter
            //Reset the round counter
            sessionStorage.removeItem('rounds');
            sessionStorage.removeItem('rounds');
            if ((popup.length !== 0) && !navbar) {
            if ((popup.length !== 0) && !navbar) {
                //End of round
                //End of round
                if (settings.skipToNextRound) {
                if (settings.skipToNextRound) {
                    //Auto-advance to next round
                    //Auto-advance to next round
                    if (settings.popupTime === 0) {
                    if (settings.popupTime === 0) {
                        window.location.href = window.location.href;
                        window.location.href = window.location.href;
                    } else {
                    } else {
                        setTimeout(function() {
                        setTimeout(function() {
                            window.location.href = window.location.href;
                            window.location.href = window.location.href;
                        }, settings.popupTime);
                        }, settings.popupTime);
                    }
                    }
                    // Mousemelee Chrome keep-on-going fix
                    // Mousemelee Chrome keep-on-going fix
                    // Store cursor position to localStorage
                    // Store cursor position to localStorage
                    // When the round changes, the whole page is reloaded, and
                    // When the round changes, the whole page is reloaded, and
                    //      curX and curY is set to its default value when it is declared.
                    //      curX and curY is set to its default value when it is declared.
                    // This stops the keep-on-going mechanism. Storing the last known
                    // This stops the keep-on-going mechanism. Storing the last known
                    //      cursor position and loading them when the page fully reloads
                    //      cursor position and loading them when the page fully reloads
                    //      fixes this issue.
                    //      fixes this issue.
                    if ( settings.mouseMelee ) {
                    if ( settings.mouseMelee ) {
                        localStorage.setItem('curX', curX);
                        localStorage.setItem('curX', curX);
                        localStorage.setItem('curY', curY);
                        localStorage.setItem('curY', curY);
                    }
                    }
                }
                }
            } else {
            } else {
                //End of battle serie
                //End of battle serie
                //Remove the record of Counter Plus
                //Remove the record of Counter Plus
                localStorage.removeItem('record');
                localStorage.removeItem('record');
            }
            }
        }
        }
        //var customEnd = (new Date()).getTime();
        //var customEnd = (new Date()).getTime();
        //console.log("CustomTime = " + (customEnd - swapEnd));
        //console.log("CustomTime = " + (customEnd - swapEnd));
        //console.log("TotalTime = " + (customEnd - loadStart));
        //console.log("TotalTime = " + (customEnd - loadStart));
    }
    }
    /* ============ UPDATE PAGE END =========== */
    /* ============ UPDATE PAGE END =========== */
}
}
/* =========== SUBMIT ACTION END ========== */
/* =========== SUBMIT ACTION END ========== */
// Start script if in battle
// Start script if in battle
if ( document.getElementById('togpane_log') ) {
if ( document.getElementById('togpane_log') ) {
    // Init
    // Init
    initialPageLoad();
    initialPageLoad();
    // Replace submit with custom submit
    // Replace submit with custom submit
    document.getElementById("battleform").submit = SubmitAction;
    document.getElementById("battleform").submit = SubmitAction;
    // Run all script modules
    // Run all script modules
    OnPageReload();
    OnPageReload();
}
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *\
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *\
 * ===========  C O R E   E N D  ========== *
 * ===========  C O R E   E N D  ========== *
\* ======================================== */
\* ======================================== */