Untitled diff

Created Diff never expires
157 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
456 lines
273 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
564 lines
// ==UserScript==
// ==UserScript==
// @name Reloader
// @name Reloader
// @namespace HVRLD3
// @namespace HVRLD3
// @author nihilvoid, Dan31
// @author nihilvoid, Dan31, FabulousCupcake, simrock87
// @run-at document-start
// @run-at document-end
// @include http://hentaiverse.org/*
// @include http://hentaiverse.org/*
// @version 1.3
// @version 1.3.1
// @grant none
// @grant none
// ==/UserScript==
// ==/UserScript==


//Vanilla Reloader: http://forums.e-hentai.org/index.php?s=&showtopic=65126&view=findpost&p=4259841
// Vanilla Reloader:
// http://forums.e-hentai.org/index.php?s=&showtopic=65126&view=findpost&p=4259841


//Select a custom font in your settings: http://hentaiverse.org/?s=Character&ss=se
// Select a custom font in your settings:
//Example: Cambria/9/bold/normal/-4
// http://hentaiverse.org/?s=Character&ss=se


//TODO (development):
// 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)


//Change your settings here
// Credits and Sources
// ------------------------
// Original reloader idea : nihilvoid
// Reloader maintainer : Dan31
// No Blinking : HV Stat

/* ======================================== *\
* ============= CONFIGURATION ============ *
\* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
var settings = {
var settings = {
//Hide the Welcome to the Hentaiverse image
hideWelcome: true, // Hide the "Welcome to the Hentaiverse" image/logo
hideWelcome: true,
noBlinking: true, // Disable buff/debuff blinking
//Disable buff/debuff blinking
effectDurations: true, // Show buff/debuff durations
noBlinking: true,
gemIcon: true, // Show gem/powerup, click on icon to use
//Show buff/debuff durations
roundCounter: true, // Show current round and rounds remaining
effectDurations: true,

//Show gem, click on icon to use
defaultAction: 0, // Change the default action to a T1 spell
gemIcon: true,
// | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
//Show current round
// | No Change | Fiery Blast | Freeze | Shockblast | Gale | Smite | Corruption |
roundCounter: true,

//Change the default action to a T1 spell
mouseMelee: true, // MouseMelee ( hover on enemies to attack )
//No change: 0, Fiery Blast: 1, Freeze: 2, Shockblast: 3, Gale: 4, Smite: 5, Corruption: 6
minHP: 0.4, // Stop if hp is below this threshold
defaultAction: 0,
minMP: 0.12, // Stop if mp ...
//Enable Mousemelee, disable it on conditions (minHP = 0.4 means disabled when HP under 40%, etc.)
minSP: 0.3, // Stop if sp ...
mouseMelee: true,
stopWhenChanneling: true, // Stop if you have channeling buff
minHP: 0.4,

minMP: 0.12,
battleLog: true, // Show battle log
minSP: 0.3,
//battleLogAppend: false, //disabled for now (need to redo this without jQuery)
stopWhenChanneling: true,

//Show the battle log
skipToNextRound: true, // Auto-advance to next round
battleLog: true,
popupTime: 0, // after `popupTime`ms
//battleLogAppend: false,//disabled for now (need to redo this without jQuery)
showPopup: false, // Show that end of round popup?
//Auto-advance to next round on round clear after set time (ms)

skipToNextRound: true,
counterPlus: true // HV-Counter-Plus ( shows turns, speed, time, exp, and credits at the end of game )
popupTime: 0,
showPopup: false,
//Enable HV Counter Plus (show turns, speed, time, exp, credits at the end of a battle serie)
counterPlus: true
};
};


//-----------------------------------------------------------------------------------------------------------------
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *\
* =========== CONFIGURATION END ========== *
\* ======================================== */


document.title = 'HV'; //Change page title to 'HV'
var sheet = document.createElement('style');
//style for round counter and effect duration
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}';
if (!settings.battleLog) {
//Hide the battle log
sheet.innerHTML += "#togpane_log {display: none}";
}
if (settings.hideWelcome) {
//Hide the 'Welcome to the Hentaiverse' image.
sheet.innerHTML += 'img.cw{display: none}.cbl:nth-of-type(1){padding-top:114px}';
}
document.head.appendChild(sheet);


//### No blinking script ###

//Disables buff/debuff blinking
/* ======================================== *\
if (settings.noBlinking) {
* ============= INITIAL LOAD ============= *
window.addEventListener('beforescriptexecute', function(e) {
\* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
if (/battle\.set_infopane\("Battle Time"\)/.test(e.target.innerHTML)) {
// Stuffs to be ran on page load
e.preventDefault();

window.removeEventListener(e.type, arguments.callee, true);
function initialPageLoad() {
// Hoverplay fix for Chrome
// 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
if ( settings.mouseMelee ) {

// Get cursor position from the last round
curX = localStorage.getItem('curX');
curY = localStorage.getItem('curY');
localStorage.removeItem('curX');
localStorage.removeItem('curY');

// Update curX and curY whenever cursor moves
if (window.Event) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = function(e) {
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);
};
}

// Change page title to "HV"
document.title = 'HV';

// Insert stylesheet for Round Counter and Effect Duration
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}';

// Hide Battle Log
if (!settings.battleLog) sheet.innerHTML += '#togpane_log {display: none}';

// Hide Welcome Logo
if (settings.hideWelcome) { sheet.innerHTML += 'img.cw{display: none}.cbl:nth-of-type(1){padding-top:114px}'; }
document.head.appendChild(sheet);

/* ============== NO BLINKING ============= */
if (settings.noBlinking) {
window.addEventListener('beforescriptexecute', function(e) {
if (/battle\.set_infopane\("Battle Time"\)/.test(e.target.innerHTML)) {
e.preventDefault();
window.removeEventListener(e.type, arguments.callee, true);
}
}, true);
}
/* ============ NO BLINKING END =========== */

/* ============= ROUND COUNTER ============ */
Text moved from lines 426-432
if (settings.roundCounter) {
var logs = document.querySelector('#togpane_log tr:nth-last-child(2)').textContent;
if (/Round/.test(logs) && !sessionStorage.rounds) {
var round = logs.match(/Round ([\d\s\/]+)/)[1];
sessionStorage.setItem('rounds', round);
} else {
var round = sessionStorage.getItem('rounds') || undefined;
}
}
Text moved with changes from lines 434-449 (98.3% similarity)
}, true);
if (round !== undefined) {
};
var x = document.getElementById('mainpane').appendChild(document.createElement('div'));
//### No blinking script - end ###
x.id = 'round';
x.innerHTML = round;
var final = round.split('/');
switch (final[1] - final[0]) {
case 0:
x.style.color = '#ff0000';
break;
case 1:
x.style.color = '#ffcc99';
break;
}
}
}
/* =========== ROUND COUNTER END ========== */

}

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *\
* =========== INITIAL LOAD END =========== *
\* ======================================== */



/* ======================================== *\
* ============ ON PAGE RELOAD ============ *
\* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
// Stuffs to be executed after the xhr request is sent
// 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.


//### Change 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;
}
}
//### Change default action - end ###
/* ========== DEFAULT ACTION END ========== */


//### HV Counter Plus ###
/* ============ HV COUNTER PLUS =========== */
if (settings.counterPlus) {
if (settings.counterPlus) {
(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,
text = 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 < text.length) {
while (i < textC.length) {
target = text[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 (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 ========= */


//### Effect duration ###
/* ============= BUFF DURATION ============ */
//From HV Stats Slim
if (settings.effectDurations) {
if (settings.effectDurations) {
(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';
}
}
})();
}
}
//### Effect duration - end ###
/* =========== BUFF DURATION END ========== */


//### Show Gems script ###
/* =============== SHOW GEMS ============== */
//Show an icon when possessing a gem, which can be clicked to use it.
if (settings.gemIcon) {
if (settings.gemIcon) {
(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 script - end ###
/* ============= SHOW GEMS END ============ */


//### custom MouseMelee script ###
/* ============== MOUSE MELEE ============= */
//Hover over monsters to attack. Stops on defined conditions.
if (settings.mouseMelee) {
if (settings.mouseMelee) {
(function(){

function getMonsterUnderCursor() {
var el = document.elementFromPoint(curX, curY);
var result = false;

// Check `el` and iteratively its parents until we hit body or found monster
while(!result) {
if(el.nodeName.toLowerCase() === 'body') break;
result = ( el.id.match('mkey') ? el : false );
el = el.parentElement;
}

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()) {
var m = mpane.getElementsByClassName("btm1");
// Check if cursor is hovering on a monster
for (var i = 0; i < m.length; i++) {
var monster = getMonsterUnderCursor();
if (m[i].hasAttribute('onclick')) {
if ( monster ) {
m[i].setAttribute('onmouseover', m[i].getAttribute('onclick'));
monster.click();
} else {
// 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'));
}
}
}
}
}
}
}
})();
}
}
//### custom MouseMelee script - end ###
/* ============ MOUSE MELEE END =========== */

}
}


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';
* ========== ON PAGE RELOAD END ========== *
\* ======================================== */


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

/* ============= 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;
}
}


//Make 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);


// Selectively replace elements on the screen
/* ============== UPDATE PAGE ============= */
function updatePage(data) {
function updatePage(data) {
var existing, newStuff, i;
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 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
var existing = document.querySelectorAll(replacements);
existing = document.querySelectorAll(replacements);
var newStuff = data.querySelectorAll(replacements);
newStuff = data.querySelectorAll(replacements);
var 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)
var existing = document.querySelectorAll(monsterReplacements);
existing = document.querySelectorAll(monsterReplacements);
var newStuff = data.querySelectorAll(monsterReplacements);
newStuff = data.querySelectorAll(monsterReplacements);
var 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
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");
}
}
if (popup.length != 0) {

// Popup
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);
}
}
}
}


// Do everything again
//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
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
// Store cursor position to localStorage
// When the round changes, the whole page is reloaded, and
// curX and curY is set to its default value when it is declared.
// This stops the keep-on-going mechanism. Storing the last known
// cursor position and loading them when the page fully reloads
// fixes this issue.
if ( settings.mouseMelee ) {
localStorage.setItem('curX', curX);
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 =========== */


}
}

/* =========== SUBMIT ACTION END ========== */
// Run this stuff after the page is loaded
addEventListener('DOMContentLoaded', OnPageLoad, false);
function OnPageLoad() {

// TODO: One-time stuff that happens on page load should go here


//Exit if not in a battle
// Start script if in battle
if (!document.getElementById('togpane_log')) {
if ( document.getElementById('togpane_log') ) {
return;
}


//### Round counter ###
// Init
Text moved to lines 116-122
if (settings.roundCounter) {
initialPageLoad();
var logs = document.querySelector('#togpane_log tr:nth-last-child(2)').textContent;
if (/Round/.test(logs) && !sessionStorage.rounds) {
var round = logs.match(/Round ([\d\s\/]+)/)[1];
sessionStorage.setItem('rounds', round);
} else {
var round = sessionStorage.getItem('rounds') || undefined;
}
Text moved with changes to lines 124-139 (98.3% similarity)
if (round !== undefined) {
var x = document.getElementById('mainpane').appendChild(document.createElement('div'));
x.id = 'round';
x.innerHTML = round;
var final = round.split('/');
switch (final[1] - final[0]) {
case 0:
x.style.color = '#ff0000';
break;
case 1:
x.style.color = '#ffcc99';
break;
}
}
}
//### Round counter - end ###


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


// Run all script modules
OnPageReload();
OnPageReload();
}
}


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