// ==UserScript==
// @name Pardus Clock
// @namespace pardus.at
// @author Rhindon
// @version 4.2
// @description Displays tick timers for the online game Pardus
// @include http*://*.pardus.at/msgframe.php
// @include http*://*.pardus.at/main.php
// ==/UserScript==
//Set the location of your clock
var showInMsgBar = true;
var showInRightCol = true;
var showUnderNav = false;
//Change the "true" to "false" to hide a given counter.
var showLocalTime = true;
var showGMT = true;
var showAP = true;
var showBuilding = true;
var showPlanet = true;
var showStarbase = true;
var showEMatter = true;
var showMonsters = true;
//Time Offsets (Hours)
// To add two hours, use '2', to subtract two hours use '-2'
var OffsetAll = 2;
var localTimeOs = 0;
var GMTOs = 0;
var BuildingOs = 0;
var PlanetOs = 0;
var StarbaseOs = 0;
//Number of Seconds between Updates
var resolution = 1;
//
//
//End of user-editable settings
//
//
if(document.URL.indexOf('main.php') == -1) {
showInRightCol = false;
showUnderNav = false;
}
if(document.URL.indexOf('msgframe.php') == -1) {
showInMsgBar = false;
}
window.addEventListener("load",init,false);
function setColor(id, yrate, rrate) {
if(showInMsgBar ) changeColor("msg_" + id, yrate, rrate);
if(showInRightCol) changeColor("rc_" + id, yrate, rrate);
if(showUnderNav ) changeColor("un_" + id, yrate, rrate);
}
function changeColor(id, yrate, rrate) {
x = document.getElementById(id);
y = document.getElementById(id + "lbl");
var timer = Number(document.getElementById(id).innerHTML.replace(':', '').replace(':', ''));
yrate = Number(yrate);
rrate = Number(rrate);
if(timer > yrate) {
x.style.color = 'white';
y.style.color = 'white';
}
if(timer <= yrate && timer > rrate) {
x.style.color = 'yellow';
y.style.color = 'yellow';
}
if(timer <= rrate) {
x.style.color = 'red';
y.style.color = 'red';
}
}
//by Spoilerhead 2006
//licenced by GPL v2 (and only v2!)
function showFilled(Value) {
return (Value > 9) ? "" + Value : "0" + Value;
}
function formatTime(hours, minutes, seconds) {
return showFilled(hours) + ":" + showFilled(minutes) + ":" + showFilled(seconds);
}
function updateHTML(id, text) {
if(showInMsgBar && document.getElementById("msg_" + id)) document.getElementById("msg_" + id).innerHTML = text;
if(showInRightCol && document.getElementById("rc_" + id)) document.getElementById("rc_" + id).innerHTML = text;
if(showUnderNav && document.getElementById("un_" + id)) document.getElementById("un_" + id).innerHTML = text;
}
function StartClock24() {
var hours = 0;
var minutes = 0;
var seconds = 0;
dst = OffsetAll;
TheTime = new Date;
minutes = TheTime.getMinutes();
seconds = TheTime.getSeconds();
if(showLocalTime) {
hours = (TheTime.getHours() % 24) + localTimeOs;
updateHTML("tim", formatTime(hours, minutes, seconds));
}
if(showGMT) {
hours = TheTime.getUTCHours() + GMTOs;
updateHTML("gmt", formatTime(hours, minutes, seconds));
}
hours = 0;
seconds = 59-TheTime.getSeconds();
if(showAP) {
minutes = 5-TheTime.getMinutes() % 6;
updateHTML("ap", formatTime(hours, minutes, seconds));
setColor("ap", "000100", "000010");
}
if(showMonsters) {
minutes = 8 - TheTime.getMinutes() % 9;
updateHTML("mon", formatTime(hours, minutes, seconds));
setColor("mon", "000200", "000030");
}
if(showEMatter) {
minutes = 59-TheTime.getMinutes() % 60 + 31;
if(minutes > 60) {
minutes = minutes - 60;
hours = hours + 1;
}
updateHTML("em", formatTime(hours, minutes, seconds));
setColor("em", "000500", "000200");
}
x = TheTime.getMinutes();
x = x - 25;
if (x < 0)
{
x = x + 60;
TheTime.setHours(TheTime.getHours()-1);
}
TheTime.setMinutes(x);
TheTime.setHours(TheTime.getUTCHours() + dst + 3);
minutes = 59-TheTime.getMinutes();
seconds = 59-TheTime.getSeconds();
//Building Ticks
if(showBuilding) {
hours = 5 - (TheTime.getHours() % 6) + BuildingOs;
updateHTML("bui", formatTime(hours, minutes, seconds));
setColor("bui", "001000", "000500");
}
//Planet Ticks
if(showPlanet) {
hours = 2 - ((TheTime.getHours() + 2) % 3) + PlanetOs;
updateHTML("pl", formatTime(hours, minutes, seconds));
setColor("pl", "001000", "000500");
}
//Starbase Ticks
if(showStarbase) {
hours = 2 - ((TheTime.getHours() + 1) % 3) + StarbaseOs;
updateHTML("sb", formatTime(hours, minutes, seconds));
setColor("sb", "001000", "000500");
}
var multiplier = seconds % resolution;
if (multiplier < 1) {
multiplier = resolution;
}
setTimeout(StartClock24,1000 * multiplier);
}
var msg_html = "";
if(showInMsgBar) {
msg_html = "";
if(showLocalTime) msg_html = msg_html + " Time: | ";
if(showGMT ) msg_html = msg_html + " GMT: | ";
if(showAP ) msg_html = msg_html + " AP: | ";
if(showBuilding ) msg_html = msg_html + " Building: | ";
if(showPlanet ) msg_html = msg_html + " Planet: | ";
if(showStarbase ) msg_html = msg_html + " Starbase: | ";
if(showEMatter ) msg_html = msg_html + " E-Matter: | ";
if(showMonsters ) msg_html = msg_html + " Monsters: | ";
msg_html = msg_html + "
";
if(showLocalTime) msg_html = msg_html + " 08:13:55 | ";
if(showGMT ) msg_html = msg_html + " 06:13:55 | ";
if(showAP ) msg_html = msg_html + " 00:04:04 | ";
if(showBuilding ) msg_html = msg_html + " 03:11:04 | ";
if(showPlanet ) msg_html = msg_html + " 01:11:04 | ";
if(showStarbase ) msg_html = msg_html + " 02:11:04 | ";
if(showEMatter ) msg_html = msg_html + " 00:04:04 | ";
if(showMonsters ) msg_html = msg_html + " 00:04:04 | ";
msg_html = msg_html + "
";
}
var rc_html = "";
if(showInRightCol) {
rc_html = rc_html + "";
rc_html = rc_html + " ";
rc_html = rc_html + " ";
rc_html = rc_html + " ";
rc_html = rc_html + " | ";
rc_html = rc_html + "
";
rc_html = rc_html + " ";
rc_html = rc_html + " ";
rc_html = rc_html + " ";
if(showLocalTime) rc_html = rc_html + " Time: | 08:13:55 | ";
if(showGMT ) rc_html = rc_html + " GMT: | 06:13:55 | ";
if(showAP ) rc_html = rc_html + " AP: | 00:04:04 | ";
if(showBuilding ) rc_html = rc_html + " Building: | 03:11:04 | ";
if(showPlanet ) rc_html = rc_html + " Planet: | 01:11:04 | ";
if(showStarbase ) rc_html = rc_html + " Starbase: | 02:11:04 | ";
if(showEMatter ) rc_html = rc_html + " E-Matter: | 00:04:04 | ";
if(showMonsters ) rc_html = rc_html + " Monsters: | 00:04:04 | ";
rc_html = rc_html + " ";
rc_html = rc_html + " | ";
rc_html = rc_html + "
";
rc_html = rc_html + " ";
rc_html = rc_html + " ";
rc_html = rc_html + " ";
rc_html = rc_html + " | ";
rc_html = rc_html + "
";
rc_html = rc_html + "
";
}
var un_html = "";
if(showUnderNav) {
un_html = "";
un_html = un_html + " | ";
un_html = un_html + ""
un_html = un_html + " "
if(showLocalTime) un_html = un_html + " Time: | ";
if(showGMT ) un_html = un_html + " GMT: | ";
if(showAP ) un_html = un_html + " AP: | ";
if(showBuilding ) un_html = un_html + " Building: | ";
if(showPlanet ) un_html = un_html + " Planet: | ";
if(showStarbase ) un_html = un_html + " Starbase: | ";
if(showEMatter ) un_html = un_html + " E-Matter: | ";
if(showMonsters ) un_html = un_html + " Monsters: | ";
un_html = un_html + "";
if(showLocalTime) un_html = un_html + " 08:13:55 | ";
if(showGMT ) un_html = un_html + " 06:13:55 | ";
if(showAP ) un_html = un_html + " 00:04:04 | ";
if(showBuilding ) un_html = un_html + " 03:11:04 | ";
if(showPlanet ) un_html = un_html + " 01:11:04 | ";
if(showStarbase ) un_html = un_html + " 02:11:04 | ";
if(showEMatter ) un_html = un_html + " 00:04:04 | ";
if(showMonsters ) un_html = un_html + " 00:04:04 | ";
un_html = un_html + " ";
un_html = un_html + " ";
un_html = un_html + " | | |
";
}
function init() {
if(showInMsgBar && document.URL.indexOf('msgframe.php') >= 0) {
var table = document.getElementsByTagName('table');
if(table[0].firstChild.firstChild.childNodes[2].innerHTML.replace(/^\s+|\s+$/g, '') == '')
{
var e = table[0].firstChild.firstChild.childNodes[2];
var child = document.createElement('table');
child.setAttribute('align', 'center');
child.setAttribute('style', "background-image:url('http://static.pardus.at/images/bgmedium.gif'); border-style:ridge; border-color:#2b2b51; border-width:2px; font-weight:bold; font-size:11px; color:#CCCCCC; font-family: arial, verdana, sans-serif");
child.setAttribute('cellpadding', '1');
child.setAttribute('cellspacing', '0');
child.innerHTML = msg_html;
e.appendChild(child);
}
}
if(showInRightCol && document.URL.indexOf('main.php') >= 0) {
var div = document.getElementsByTagName('div');
//search for the parent table of the cargo section
var table = document.getElementsByTagName('table');
for(i = 0; i < table.length; i++)
{
if(table[i].innerHTML.indexOf('cargo.png') != -1)
var e = table[i].parentNode;
}
var temp = e.innerHTML;
temp = rc_html + temp;
e.innerHTML = temp;
}
if(showUnderNav && document.URL.indexOf('main.php') >= 0) {
var child = document.createElement("div")
child.setAttribute("class", "pardusclock");
child.setAttribute("style", "position: absolute; top: 500px;");
child.innerHTML = un_html
document.body.insertBefore(child, document.body.lastChild);
}
StartClock24();
}