Untitled diff

Created Diff never expires
96 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
606 lines
102 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
600 lines
// ==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.2b
// @version 1.3.3
// @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
// - Hoverplay instead of mousemelee+defaultaction
// - add Hoheneim's additions
// - Fix round counter display at end of game
// - fix round counter display at end of battle serie
// - 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
// HV Counter Plus : OMP, Superlatanium
// HV State HP : tatarime


/* ======================================== *\
/* ======================================== *\
* ============= 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
hvStateHP: true, // Show enemy HP value
hvStateHP: true, // Show enemy HP value
fluidHPBar: true, // Shorten HP Bar width to easily see which monster has the most HP
fluidHPBar: true, // Shorten HP Bar width to easily see which monster has the most HP


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.35, // Stop if hp is below this threshold
minMP: 0.12, // Stop if mp ...
minMP: 0.2 , // 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
chromeFix: true, // Fix MM things on chrome by manually tracking cursor movement


battleLog: true, // Show battle log
battleLog: true, // Show battle log


skipToNextRound: true, // Auto-advance to next round
skipToNextRound: true, // Auto-advance to next round
popupTime: 0, // after `popupTime`ms
popupTime: 0, // after `popupTime`ms


counterPlus: true // HV-Counter-Plus ( shows turns, speed, time, exp, and credits at the end of game )
counterPlus: true, // HV-Counter-Plus ; log and show turn/speed/time/exp/credits
counterPlusSave: true // Store additional datas for Income Summary by Superlatanium
};
};


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *\
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *\
* =========== 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 && settings.chromeFix ) {


// 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}.hvhp{width:inherit;display:block;position:absolute;top:0;text-align:center;font-weight:bold;color:#ff0;font-size:10px;z-index:999;white-space:nowrap;text-shadow:-1px -1px #000, -1px 1px #000, 1px -1px #000, 1px 1px #000}.chbd>img{height:12px;}';
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}.hvhp{width:inherit;display:block;position:absolute;top:0;text-align:center;font-weight:bold;color:#ff0;font-size:10px;z-index:999;white-space:nowrap;text-shadow:-1px -1px #000, -1px 1px #000, 1px -1px #000, 1px 1px #000}.chbd>img{height:12px;}';


// 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) {
(function(){
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) {
(function(){
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)) {
if (/Round/.test(logs)) {
var round = logs.match(/Round ([\d\s\/]+)/)[1];
var round = logs.match(/Round ([\d\s\/]+)/)[1];
localStorage.setItem('rounds', round);
localStorage.setItem('rounds', round);
} else {
} else {
var round = localStorage.getItem('rounds') || undefined;
var round = localStorage.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) : {'turns': 0, 'time': 0, 'EXP': 0, 'Credits': 0 },
var record = (localStorage.record) ?
pop = document.getElementsByClassName('btcp')[0],
JSON.parse(localStorage.record) :
set = function() { localStorage.setItem('record', JSON.stringify(record)); },
{'turns': 0, 'time': 0, 'EXP': 0, 'Credits': 0, 'rounds': 0 };
build = function(item, point) { record[item] = record[item] * 1 + point * 1; };

var pop = document.getElementsByClassName('btcp')[0];

function set() {
record.rounds++;
localStorage.setItem('record', JSON.stringify(record));
}

function build(item, point) {
record[item] = parseInt(record[item]) || 0 + parseInt(point);
// parseInt(null) is NaN, `|| 0` so it's 0.
}


if (!record.time) {
if (!record.time) {
build('time', Date.now());
build('time', Date.now());
set();
set();
}
}


// If there's a popup...
if (pop) {
if (pop) {

// Fetch amount of turns taken to complete the round
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);


// And find for credit drops
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; // stop at end
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 there's an image in the popup ( the continue button; signifying "not game end" )...
else {
if (pop.getElementsByTagName('img')[0]) {
// Save it to storage and we're done
set();
} else {
// No image! It's game end! Display the stats and then burn it.
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';
div.style.marginRight = '7px';
div.style.marginLeft = '7px';
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++;
}
}

// Counter Plus Save for _Income Summary_ by superlatanium
if ( settings.counterPlusSave ) {
var cpsLogs = (localStorage.counterPlusSaveLogs) ?
JSON.parse(localStorage.counterPlusSaveLogs) :
[];

cpsLogs.push({
rounds: record.rounds,
turns: record.turns,
runTime: runTime,
timestamp: Date.now()
});

localStorage.counterPlusSaveLogs = JSON.stringify(cpsLogs);
}
}
}
}
}
})();
})();
}
}
/* ========== 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();
if ( settings.chromeFix ) {
if ( monster && monster.onclick !== null ) {
var monster = getMonsterUnderCursor();
monster.click();
if ( monster && monster.onclick !== null ) {
} else {
monster.click();
// Add hover event listeners
return;
var m = mpane.getElementsByClassName("btm1");
}
for (var i = 0; i < m.length; i++) {
}
if (m[i].hasAttribute('onclick')) {

m[i].setAttribute('onmouseover', m[i].getAttribute('onclick'));
// Add hover event listeners
}
var m = mpane.getElementsByClassName("btm1");
for (var i = 0; i < m.length; i++) {
if (m[i].hasAttribute('onclick')) {
m[i].setAttribute('onmouseover', m[i].getAttribute('onclick'));
}
}
}
}
}
}
})();
})();
}
}
/* ============ MOUSE MELEE END =========== */
/* ============ MOUSE MELEE END =========== */


/* ============== HV STATE HP ============= */
/* ============== HV STATE HP ============= */
if(settings.hvStateHP) {
if(settings.hvStateHP) {
(function(){
(function(){


function writeHP(index, value) {
function writeHP(index, value) {
var targ = document.querySelectorAll('.btm5:first-child')[index];
var targ = document.querySelectorAll('.btm5:first-child')[index];
if ( targ.children[0].src == 'http://ehgt.org/v/s/nbardead.png' ) return; // Skip if dead
if ( targ.children[0].src == 'http://ehgt.org/v/s/nbardead.png' ) return; // Skip if dead
var realHPperc = targ.children[0].children[0].width/120;
var realHPperc = targ.children[0].children[0].width/120;
var realHP = Math.round( realHPperc * value );
var realHP = Math.round( realHPperc * value );
var maxHP = value;
var maxHP = value;
var el = document.createElement('span');
var el = document.createElement('span');
el.classList.add('hvhp');
el.classList.add('hvhp');
el.innerHTML = `${realHP} / ${maxHP}`;
el.innerHTML = `${realHP} / ${maxHP}`;


targ.appendChild(el);
targ.appendChild(el);
}
}
function changeHPBarWidth(index, value, maxvalue) {
function changeHPBarWidth(index, value, maxvalue) {
var targ = document.querySelectorAll('.btm5:first-child')[index];
var targ = document.querySelectorAll('.btm5:first-child')[index];
if ( targ.children[0].src == 'http://ehgt.org/v/s/nbardead.png' ) return; // Skip if dead
if ( targ.children[0].src == 'http://ehgt.org/v/s/nbardead.png' ) return; // Skip if dead
var realwidth = targ.children[0].children[0].width;
var realwidth = targ.children[0].children[0].width;
var maxwidth = 120;
var maxwidth = 120;
realwidth = Math.round(realwidth * value/maxvalue);
realwidth = Math.round(realwidth * value/maxvalue);
maxwidth = Math.round( maxwidth * value/maxvalue);
maxwidth = Math.round( maxwidth * value/maxvalue);


targ.style.width = `${maxwidth}px`;
targ.style.width = `${maxwidth}px`;
targ.children[0].style.width = `${maxwidth}px`;
targ.children[0].style.width = `${maxwidth}px`;
targ.children[0].children[0].style.width = `${realwidth}px`;
targ.children[0].children[0].style.width = `${realwidth}px`;
targ.children[0].children[1].style.width = `${maxwidth}px`;
targ.children[0].children[1].style.width = `${maxwidth}px`;
}
}
function fetchMonsterHPs() {
function fetchMonsterHPs() {
var i = 0;
var i = 0;
var hpList = '';
var hpList = '';


while(true) {
while(true) {
index = 3 + i;
index = 3 + i;
var log = document.querySelector(`#togpane_log tr:nth-last-child(${index})`);
var log = document.querySelector(`#togpane_log tr:nth-last-child(${index})`);
if ( log && /Spawned Monster/.test(log.textContent) ) {
if ( log && /Spawned Monster/.test(log.textContent) ) {
var hp = log.textContent.match(/HP=(\d+)/)[1];
var hp = log.textContent.match(/HP=(\d+)/)[1];
hpList += `${hp};`;
hpList += `${hp};`;
} else {
} else {
break;
break;
}
}
i += 1;
i += 1;
}
}


if (hpList) localStorage.setItem('hpList', hpList);
if (hpList) localStorage.setItem('hpList', hpList);
}
}
function isBattleStart() {
function isBattleStart() {
var log = document.querySelector('#togpane_log tr:nth-last-child(1)').textContent;
var log = document.querySelector('#togpane_log tr:nth-last-child(1)').textContent;
if ( /Battle Start!/.test(log) ) return true;
if ( /Battle Start!/.test(log) ) return true;
return false;
return false;
}
}


// Get list of monster HP
// Get list of monster HP
if ( isBattleStart() ) fetchMonsterHPs();
if ( isBattleStart() ) fetchMonsterHPs();
var hpList = localStorage.getItem('hpList');
var hpList = localStorage.getItem('hpList');
if( typeof hpList == "undefined" ) return;
if( typeof hpList == "undefined" ) return;
hpList = hpList.split(';');
hpList = hpList.split(';');


// Write HP to each monster
// Write HP to each monster
for(var i = 0; i<hpList.length-1; i+=1) {
for(var i = 0; i<hpList.length-1; i+=1) {
writeHP(i, hpList[i]);
writeHP(i, hpList[i]);
}
}


// Fluid HP bar
// Fluid HP bar
if(settings.fluidHPBar) {
if(settings.fluidHPBar) {
var maxHP = Math.max.apply(null, hpList);
var maxHP = Math.max.apply(null, hpList);
for(var i = 0; i<hpList.length-1; i+=1) {
for(var i = 0; i<hpList.length-1; i+=1) {
changeHPBarWidth(i, hpList[i], maxHP);
changeHPBarWidth(i, hpList[i], maxHP);
}
}
}
}


})();
})();
}
}
/* ============ HV STATE HP END =========== */
/* ============ HV STATE HP END =========== */


/* =========== EXTERNAL SCRIPTS =========== */
window.dispatchEvent(new CustomEvent('Reloader_reloaded'));
}
}


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *\
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *\
* ========== ON PAGE RELOAD END ========== *
* ========== ON PAGE RELOAD END ========== *
\* ======================================== */
\* ======================================== */




/* ======================================== *\
/* ======================================== *\
* =============== C O R E ============== *
* =============== C O R E ============== *
\* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
\* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */


/* ============= SUBMIT ACTION ============ */
/* ============= SUBMIT ACTION ============ */
function SubmitAction() {
function SubmitAction() {
// Reload page if end of round detected ( marked by the existence of popup/navbar )
// Reload page if end of round detected ( marked by the existence of popup/navbar )
if (document.querySelector('.btcp') || document.querySelector('#navbar')) {
if (document.querySelector('.btcp') || document.querySelector('#navbar')) {
window.location.href = window.location.href;
window.location.href = window.location.href;
return;
return;
}
}


// Serialize form data
// Serialize 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 XHR
// Send XHR
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';


// Replace `replacements` elements on live document with the newly obtained data
// Replace `replacements` elements on live document with the newly obtained data
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]);
}
}


// Replace `monsterReplacements` elements on live document with the newly obtained data
// Replace `monsterReplacements` elements on live document with the newly obtained data
// Don't update dead monsters
// Don't update 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');


var popupLength = popup.length; // this is because popup.length is changed after insertBefore() is called for some reason.
var navbarExists = !!navbar;

// If there's navbar/popup in new content, show it
// If there's navbar/popup in new content, show it
if (navbar) {
if (navbarExists) {
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");
}
}
if (popup.length !== 0) {
if (popupLength !== 0) {
var parent = document.getElementsByClassName('btt')[0];
// Here we're loading popup to the page regardless of the skipNextRound / popupTime settings
parent.insertBefore(popup[0], parent.firstChild);
// even though it is "skipped" and not even visible; slightly increasing load time.
}
// This is because OnPageReload() will later call scripts,

// some of which will require popup in the document ( Counter Plus )
// for some strange reason, popup.length becomes 0 now, refetch it from document :/
var parent
popup = document.getElementsByClassName('btcp');
navbar = document.getElementById('navbar');

// Run all script modules again
OnPageReload();

// Reload page if `skipToNextRound` and it is Round End
// Round End detection: popup exists and navbar does not
if ( popup.length !== 0 && !navbar ) {
/*
if ( settings.mouseMelee ) {
localStorage.setItem('curX', curX);
localStorage.setItem('curY', curY);
}
*/
// Skip to next round
if ( settings.skipToNextRound ) {
if (settings.popupTime === 0) {
window.location.href = window.location.href;
} else {
setTimeout(function() {
window.location.href = window.location.href;
}, settings.popupTime);
}
}
}

// Remove counter datas on Game End
// Game End detection: popup and navbar exists
if ( popup.length !== 0 && navbar ) {
localStorage.removeItem('record');
localStorage.removeItem('rounds');
}

}
/* ============ UPDATE PAGE END =========== */

}
/* =========== SUBMIT ACTION END ========== */

// Start script if in battle
if ( document.getElementById('togpane_log') ) {

// Init
initialPageLoad();

// Replace submit with custom submit
document.getElementById("battleform").submit = SubmitAction;

// Run all script modules
OnPageReload();
}

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *\
* =========== C O R E E N D ========== *
\* ======================================== */