Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pardus_combat_screen_skills.user.js
// ==UserScript==
// @name Pardus Combat Screen Skills
// @namespace Pardus
// @author Tro
// @version 1.2
// @description Adds your combat skills onto the combat page
// @downloadURL https://gist.github.com/Tro95/1df4c595c921f5f16d170b0daed09f8a/raw/pardus_combat_screen_skills.user.js
// @updateURL https://gist.github.com/Tro95/1df4c595c921f5f16d170b0daed09f8a/raw/pardus_combat_screen_skills.user.js
// @include http*://*.pardus.at/ship2opponent_combat.php*
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @connect *
// ==/UserScript==
// = Change log =
// v1.2 Fixed boosted skills not being parsed correctly, and added background load to prevent box from flashing
(function() {
'use strict';
var previous_skills = GM_getValue(document.location.hostname + '_skills',
{
tactics: {
base: '00.00',
actual: '00.00'
},
hit_accuracy: {
base: '00.00',
actual: '00.00'
},
maneuver: {
base: '00.00',
actual: '00.00'
},
weaponry: {
base: '00.00',
actual: '00.00'
},
engineering: {
base: '00.00',
actual: '00.00'
}
});
var table = build_html_table(previous_skills);
document.body.appendChild(table);
var skills_url = document.location.protocol + '//' + document.location.hostname + '/overview_stats.php';
console.log('making the request');
if (typeof GM_xmlhttpRequest !== "undefined") {
GM_xmlhttpRequest({
method: 'GET',
url: skills_url,
onabort: function(response) {
console.log(response.responseText);
},
onload: function(response) {
//console.log(response.responseText);
console.log(match_skill(response.responseText, 'weaponry_actual'));
//console.log(match_skill("<td id='tactics_base'>60.29</td>", 'tactics_base'));
var skills = parse_skills(response.responseText);
GM_setValue(document.location.hostname + '_skills', skills);
update_html_table(skills);
},
onerror: function(error) {
console.log(error.responseText);
}
});
} else {
console.log("GM_xmlhttpRequest is undefinied!");
}
console.log('made it');
})();
function parse_skills(skills_html) {
var skills = {
tactics: {
base: match_skill(skills_html, 'tactics_base'),
actual: match_skill(skills_html, 'tactics_actual')
},
hit_accuracy: {
base: match_skill(skills_html, 'hit_base'),
actual: match_skill(skills_html, 'hit_actual')
},
maneuver: {
base: match_skill(skills_html, 'maneuver_base'),
actual: match_skill(skills_html, 'maneuver_actual')
},
weaponry: {
base: match_skill(skills_html, 'weaponry_base'),
actual: match_skill(skills_html, 'weaponry_actual')
},
engineering: {
base: match_skill(skills_html, 'engineering_base'),
actual: match_skill(skills_html, 'engineering_actual')
}
};
return skills;
}
function match_skill(skills_html, skill) {
var regex_actual = RegExp("<td\\s*id=['\"]" + skill + "['\"]>(?:<font\\s*color=['\"]green['\"]>)?\\d{1,3}\\.?\\d{0,2}?(?:</font>)?<br><font size=['\"]1['\"] color=['\"]#66CCFF['\"]>(\\d{1,3}(\\.\\d{0,2})?)");
var regex_base = RegExp("<td\\s*id=['\"]" + skill + "['\"]>(\\d{1,3}(\\.\\d{0,2})?)");
var result = skills_html.match(regex_actual);
if (result == null) {
result = skills_html.match(regex_base);
}
return result[1];
}
function add_colour(skill, skill_level) {
var skill_html = '';
switch (skill) {
case 'tactics':
if (parseInt(skill_level) >= 65) {
return '<span style="background-color:#003300">' + skill_level + "</span>";
}
break;
case 'hit_accuracy':
if (parseInt(skill_level) >= 70) {
return '<span style="background-color:#003300">' + skill_level + "</span>";
}
break;
case 'maneuver':
if (parseInt(skill_level) >= 65) {
return '<span style="background-color:#003300">' + skill_level + "</span>";
}
break;
case 'weaponry':
if (parseInt(skill_level) >= 40) {
return '<span style="background-color:#003300">' + skill_level + "</span>";
}
break;
case 'engineering':
if (parseInt(skill_level) >= 33) {
return '<span style="background-color:#003300">' + skill_level + "</span>";
}
break;
}
return skill_level;
}
function build_html_table(skills) {
var table = document.createElement('table');
var table_html = '';
table.setAttribute('class', 'messagestyle');
table.style.backgroundImage = document.querySelector('table.messagestyle').style.backgroundImage;
table.style.position = 'absolute';
table.style.top = '20px';
table.style.left = '20px';
table_html += '<tr>';
table_html += '<th>Skill</th>';
table_html += '<th>Base</th>';
table_html += '<th>Actual</th>';
table_html += '</tr>';
table_html += '<tr><td>Tactics</td><td><div id="tactics-base">' + add_colour('tactics', skills.tactics.base) + '</div></td><td><div id="tactics-actual">' + skills.tactics.actual + '</div></td></tr>';
table_html += '<tr><td>Hit accuracy</td><td><div id="ha-base">' + add_colour('hit_accuracy', skills.hit_accuracy.base) + '</div></td><td><div id="ha-actual">' + skills.hit_accuracy.actual + '</div></td></tr>';
table_html += '<tr><td>Maneuver</td><td><div id="maneuver-base">' + add_colour('maneuver', skills.maneuver.base) + '</div></td><td><div id="maneuver-actual">' + skills.maneuver.actual + '</div></td></tr>';
table_html += '<tr><td>Weaponry</td><td><div id="weaponry-base">' + add_colour('weaponry', skills.weaponry.base) + '</div></td><td><div id="weaponry-actual">' + skills.weaponry.actual + '</div></td></tr>';
table_html += '<tr><td>Engineering</td><td><div id="engineering-base">' + add_colour('engineering', skills.engineering.base) + '</div></td><td><div id="engineering-actual">' + skills.engineering.actual + '</div></td></tr>';
table.innerHTML = table_html;
return table;
}
function update_html_table(skills) {
document.getElementById('tactics-base').innerHTML = add_colour('tactics', skills.tactics.base);
document.getElementById('ha-base').innerHTML = add_colour('hit_accuracy', skills.hit_accuracy.base);
document.getElementById('maneuver-base').innerHTML = add_colour('maneuver', skills.maneuver.base);
document.getElementById('weaponry-base').innerHTML = add_colour('weaponry', skills.weaponry.base);
document.getElementById('engineering-base').innerHTML = add_colour('engineering', skills.engineering.base);
document.getElementById('tactics-actual').innerHTML = skills.tactics.actual;
document.getElementById('ha-actual').innerHTML = skills.hit_accuracy.actual;
document.getElementById('maneuver-actual').innerHTML = skills.maneuver.actual;
document.getElementById('weaponry-actual').innerHTML = skills.weaponry.actual;
document.getElementById('engineering-actual').innerHTML = skills.engineering.actual;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.