Created
May 7, 2017 14:26
-
-
Save Tro95/fea64a8faa0e748259acf404cae001d3 to your computer and use it in GitHub Desktop.
Pardus Druggy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Pardus Druggy | |
// @namespace Pardus | |
// @description Keep track of your druggenness... | |
// @include http*://*.pardus.at/main.php* | |
// @include http*://*.pardus.at/msgframe.php* | |
// @include http*://*.pardus.at/ship2opponent_combat.php* | |
// @include http*://*.pardus.at/ship2ship_combat.php* | |
// @include http*://*.pardus.at/logout.php* | |
// @version 1.0 | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// @grant GM_xmlhttpRequest | |
// @updateURL about:blank | |
// ==/UserScript== | |
// v1.5 - Removed all tracking elements and enabled easy compatability with other scripts. | |
// v1.4 - Minor additions by Tro (Artemis) / Troo (Orion) to display druggy on the logout screen. | |
// v1.3 - minor changes by Miche (Orion) / Sparkle (Artemis) to accomodate hosting of druggy tracker | |
// - configured the script to use the drug tracker now available on http://druggy.thewaistelands.info | |
// - added version data, new grant directives for compatibility | |
// - added updateURL to point to invalid location so as to prevent auto updating of the script | |
// Beta v1.11 - Made more robust again, also added host variable, and additional config for moving from msg to main frame. | |
// v1.10 - Made more robust when there is a failure communicating with the server. | |
// v1.9 - Added password field to user config for multiCompFile on server. | |
// v1.8 - Changed color when undrugged but still TC drugginess drop available. | |
// v1.7 - Added multi computer support. Also filtering logs to avoid duplicates. | |
// - And... altered things a bit to allow for multiple users using the same computer. | |
// v1.6 - Added logging to external webserver (not the pardus servers!) for scientific purposes. | |
// v1.5 - Fixed bug. | |
// v1.4 - Fixed bug. | |
// v1.3 - Fixed bug. | |
// v1.2 - added drug use detection when in combat. | |
// | |
// Created by: Mentor in Pegasus | |
// Ideas and help by many members of Federation Underground! | |
// | |
// - here, indicate if you want it in the msg frame, or in the status box on the main frame | |
var showInMsgFrame = false; | |
// | |
// ****** End of USER CONFIG ****** | |
var menuframe = null; | |
if(window.parent.frames.length > 0) menuframe = window.parent.frames[0].document; | |
var msgframe = null; | |
if(window.parent.frames.length > 1) msgframe = window.parent.frames[1].document; | |
var mainframe = null; | |
if(window.parent.frames.length > 2) mainframe = window.parent.frames[2].document; | |
var universe; | |
identifyUniverse(); | |
function identifyUniverse() { | |
switch (document.location.hostname) { | |
case "orion.pardus.at": | |
universe = "orion"; | |
break; | |
case "artemis.pardus.at": | |
universe = "artemis"; | |
break; | |
case "pegasus.pardus.at": | |
universe = "pegasus"; | |
break; | |
} | |
} | |
// | |
// Functions | |
// First, trap the drug submit event. | |
// | |
function mysubmit(event) { | |
// | |
// Check to see if it is the button we want, then make sure it's for drugs | |
// | |
for(var i = 0; i < mainframe.getElementsByTagName('input').length; i++) { | |
var a = mainframe.getElementsByTagName('input')[i]; | |
// Our button will have a value of 'Use' | |
if (a.value == 'Use') { | |
// ensure not the retreat button | |
if (event.target.innerHTML.search(/retreat|how many rounds/i) != -1) { | |
//alert("retreat button pressed"); | |
} else { | |
if (a.parentNode.firstChild.name == 'resid') { | |
// combat drug use. | |
var resid = a.parentNode.firstChild; | |
var amount = resid.nextSibling; | |
} else { | |
// non-combat drug use. | |
var resid = a.previousSibling.previousSibling.previousSibling; | |
var amount = resid.previousSibling.previousSibling.previousSibling; | |
} | |
// Drugs have a value of 51 (bots are 8) | |
if ((resid.getAttribute('value') == 51)&&(parseInt(amount.value))) { | |
// set overdrug and drug_time | |
var overdrug = GM_getValue(universe + "_overdrug", 0); | |
var trip_control = GM_getValue(universe + "_trip_control", 0); | |
if ((overdrug) <= 0) { | |
// we have no drugginess | |
var time = new Date(); | |
var timeMS = time.getTime() / 1000; | |
var time_now = parseInt(timeMS); | |
var last_drug_time = parseInt(GM_getValue(universe + "_drug_time",0)); | |
GM_setValue(universe + "_last_drug_time", last_drug_time); | |
GM_setValue(universe + "_drug_time", time_now); | |
GM_setValue(universe + "_lastDH", time_now); | |
} | |
overdrug = overdrug + parseInt(amount.value); | |
GM_setValue(universe + "_drugs", parseInt(amount.value)); | |
GM_setValue(universe + "_overdrug", overdrug); | |
} | |
} | |
} | |
} | |
} | |
window.addEventListener('submit', mysubmit, true); | |
// | |
// Next, When the msg frame comes up, show the initial drug time, and the drugginess as a #. | |
// | |
//window.addEventListener('load', function(e) { | |
window.addEventListener('load', function(e) { | |
if (showInMsgFrame == true) { | |
if(document.URL.indexOf('msgframe.php') >= 0) { | |
//var root = msgframe.body; | |
var table = document.getElementsByTagName('table'); | |
var root = table[0].firstChild.firstChild.childNodes[3]; | |
var Sdrug = msgframe.createElement("SPAN"); | |
var Sdrugi = msgframe.createElement("SPAN"); | |
Sdrug.id = "Sdrug"; | |
Sdrug.style.margin = "5px"; | |
Sdrugi.id = "Sdrugi"; | |
Sdrugi.style.margin = "5px"; | |
var div = msgframe.createElement("DIV"); | |
div.id = "druggy"; | |
div.setAttribute('style', "font-weight:bold; font-size:10px; color:#CCCCCC; font-family: arial, verdana, sans-serif"); | |
div.align = "right"; | |
div.appendChild(msgframe.createTextNode("DTIME:")); | |
div.appendChild(Sdrug); | |
div.appendChild(msgframe.createTextNode("DREFF:")); | |
div.appendChild(Sdrugi); | |
root.appendChild(div); | |
getdrug_timer(); | |
// if you want to update the timer more than once per minute.... | |
//window.setInterval(function() | |
//{ | |
// getdrug_timer(); | |
//}, 10000); | |
} | |
} else { | |
if(document.URL.indexOf('main.php') >= 0) { | |
//search for the parent table of the cargo section | |
var table = document.getElementsByTagName('table'); | |
//Get the picture name to search for based on the Display Location Reference | |
for(i = 0; i < table.length; i++) { | |
if(table[i].innerHTML.indexOf('status.png') != -1) { | |
var root = table[i+1].parentNode; | |
} | |
} | |
var Sdrug = mainframe.createElement("SPAN"); | |
var Sdrugi = mainframe.createElement("SPAN"); | |
Sdrug.id = "Sdrug"; | |
Sdrug.style.margin = "6px"; | |
Sdrugi.id = "Sdrugi"; | |
Sdrugi.style.margin = "6px"; | |
var div = mainframe.createElement("DIV"); | |
div.id = "druggy"; | |
div.setAttribute('style', "font-weight:bold; font-size:10px; color:#CCCCCC; font-family: arial, verdana, sans-serif"); | |
div.align = "center"; | |
div.appendChild(mainframe.createTextNode("DTIME:")); | |
div.appendChild(Sdrug); | |
div.appendChild(mainframe.createTextNode("DREFF:")); | |
div.appendChild(Sdrugi); | |
root.appendChild(div); | |
getdrug_timer(); | |
// if you want to update the timer more than once per minute.... | |
window.setInterval(function() { | |
getdrug_timer(); | |
}, 1000); | |
} | |
if(document.URL.indexOf('logout.php') >= 0) { | |
//search for the parent table of the cargo section | |
var table = document.getElementsByClassName('messagestyle'); | |
//Get the picture name to search for based on the Display Location Reference | |
for(i = 0; i < table.length; i++) { | |
if(table[i].innerHTML.indexOf('Status') != -1) { | |
var root = table[i].children[0]; | |
} | |
} | |
var Sdrug = mainframe.createElement("SPAN"); | |
var Sdrugi = mainframe.createElement("SPAN"); | |
Sdrug.id = "Sdrug"; | |
Sdrug.style.margin = "6px"; | |
Sdrugi.id = "Sdrugi"; | |
Sdrugi.style.margin = "6px"; | |
var tr1 = mainframe.createElement("tr"); | |
var tr2 = mainframe.createElement("tr"); | |
var td1 = mainframe.createElement("td"); | |
var td2 = mainframe.createElement("td"); | |
var td3 = mainframe.createElement("td"); | |
var td4 = mainframe.createElement("td"); | |
tr1.id = "druggy"; | |
tr2.id = "druggy"; | |
td1.setAttribute('style', "font-weight:bold; font-size:10px; color:#CCCCCC; font-family: arial, verdana, sans-serif"); | |
td2.setAttribute('style', "font-weight:bold; font-size:10px; color:#CCCCCC; font-family: arial, verdana, sans-serif"); | |
td3.setAttribute('style', "font-weight:bold; font-size:10px; color:#CCCCCC; font-family: arial, verdana, sans-serif"); | |
td4.setAttribute('style', "font-weight:bold; font-size:10px; color:#CCCCCC; font-family: arial, verdana, sans-serif"); | |
td1.appendChild(mainframe.createTextNode("DTIME:")); | |
td2.appendChild(Sdrug); | |
td3.appendChild(mainframe.createTextNode("DREFF:")); | |
td4.appendChild(Sdrugi); | |
tr1.appendChild(td1); | |
tr1.appendChild(td2); | |
tr2.appendChild(td3); | |
tr2.appendChild(td4); | |
root.appendChild(tr1); | |
root.appendChild(tr2); | |
getdrug_timer(); | |
// if you want to update the timer more than once per minute.... | |
window.setInterval(function() { | |
getdrug_timer(); | |
}, 1000); | |
} | |
} | |
}, false); | |
function getdrug_timer() | |
{ | |
var curtime = new Date(); | |
var difftime = new Date(); | |
var showframe; | |
var overdrug = parseInt(GM_getValue(universe + "_overdrug", 0)); | |
var drug_time = parseInt(GM_getValue(universe + "_drug_time", 0)) * 1000; | |
var lasthour = parseInt(GM_getValue(universe + "_lastDH", 0)) * 1000 | |
var trip_control = parseInt(GM_getValue(universe + "_trip_control", 0)); | |
var timeSec = curtime.getTime(); | |
// Subtract current time from drug_time. | |
var timeSince = timeSec - drug_time; | |
difftime.setTime(timeSince); | |
// frame to display values | |
if (showInMsgFrame == true) { | |
showframe = msgframe; | |
} else { | |
showframe = mainframe; | |
} | |
// initialization problems fix. | |
if (overdrug <= 0) { | |
overdrug = 0; | |
} | |
// how many hours since last checked | |
var hours = parseInt((timeSec - lasthour) / 1000 / 3600); | |
if ((hours > 0) && (overdrug > 0)) { | |
// drugginess goes down by # hours | |
var drugdiff = overdrug - hours; | |
if (drugdiff <= 0) { | |
// reset clock when DREFF goes to 0. - note only increment by overdrug*3600 | |
var zerodrug_time = (lasthour/1000) + (overdrug*3600); | |
GM_setValue(universe + "_last_drug_time", (drug_time/1000)); | |
GM_setValue(universe + "_drug_time", zerodrug_time); | |
// init display clock | |
timeSince = curtime.getTime() - (zerodrug_time*1000); | |
//timeSince = curtime.getTime() - curtime.getTime(); | |
difftime.setTime(timeSince); | |
overdrug = 0; | |
} else { | |
overdrug = drugdiff; | |
} | |
GM_setValue(universe + "_overdrug", overdrug); | |
GM_setValue(universe + "_lastDH", ((lasthour/1000) + (hours * 3600)) ); | |
} | |
showframe.getElementById("druggy").setAttribute('style', "font-weight:bold; font-size:10px; color:yellow; font-family: arial, verdana, sans-serif"); | |
if((overdrug-trip_control) >= 1 ) { | |
showframe.getElementById("Sdrug").style.color = "Red"; | |
showframe.getElementById("Sdrugi").style.color = "Red"; | |
} else { | |
if (overdrug) { | |
showframe.getElementById("Sdrug").style.color = "Yellow"; | |
showframe.getElementById("Sdrugi").style.color = "Yellow"; | |
} else { | |
showframe.getElementById("Sdrug").style.color = "Limegreen"; | |
showframe.getElementById("Sdrugi").style.color = "Limegreen"; | |
} | |
} | |
if (overdrug == 0) { | |
//showframe.getElementById("Sdrug").innerHTML = "<b>00:00</b>"; | |
showframe.getElementById("Sdrug").innerHTML = "<b>" + showTimeVal(difftime.getUTCHours()) + ":" + showTimeVal(difftime.getMinutes()) + ":" + showTimeVal(difftime.getSeconds())+"</b>"; | |
} else if ((overdrug-trip_control) > 0) { | |
showframe.getElementById("Sdrug").innerHTML = "<b>" + (overdrug-trip_control-1) + ":" + showTimeVal(parseInt(59-difftime.getMinutes())) + ":" + showTimeVal(59-difftime.getSeconds())+"</b>"; | |
} else if ((overdrug-trip_control) <= 0) { | |
showframe.getElementById("Sdrug").innerHTML = "<b>" + (overdrug-1) + ":" + showTimeVal(parseInt(59-difftime.getMinutes())) + ":" + showTimeVal(59-difftime.getSeconds())+"</b>"; | |
} | |
overdrug = overdrug - trip_control; | |
showframe.getElementById("Sdrugi").innerHTML = "<b>" + overdrug + "</b>"; | |
//var buttons = '' | |
//buttons = '<br><input type="button" id="reset2" value = "Init Drug"><br>'; | |
//msgframe.getElementById("Sdrugi").innerHTML = msgframe.getElementById("Sdrugi").innerHTML + buttons; | |
//msgframe.getElementById('reset2').addEventListener('click',resetdrug_timer,true); | |
} | |
function resetdrug_timer() | |
{ | |
var drug_time = new Date(); | |
var drugSecs = drug_time.getTime() / 1000; | |
var drugint = parseInt(drugSecs); | |
drugint = drugint - (59*60); | |
GM_setValue(universe + "_overdrug",1); | |
GM_setValue(universe + "_drug_time",drugint); | |
GM_setValue(universe + "_lastDH",drugint); | |
} | |
function showTimeVal(value) | |
{ | |
return (value > 9) ? "" + value : "0" + value; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment