// Opera UserJS - Countdown script for forumwarz.com
// This will place the countdown timer into the title
// Author: TT
// v1.4.1
//set these variables for the 'options'
var useShort=true; //set to false if you prefer long string as title
var useExShort=false; //only uses biggest value (e.g. only days). trumps useShort.
var spacer=''; //default is a 'nothing' for the spacer. use ' ' for a space
var useZeros=false; //show 0 days/hours/minutes as '0' instead of excluding them
var trackIncit=true;
var trackDomination=true;
var trackAuctions=true;
var trackVisits=true; //track time until visits reload (also deliveries) on /character/me
var trackItemBuildr=true;
var trackForumBuildr=true;
var allowEnd=true; //stop the timer (don't loop past 0) and exit for FB,IB,Me. auctions always end.
var debug=false; //use with javascript:dbg() in address bar to find problems
var debugVerbose=false; //use with caution. can eat memory with lots of text
// !!! DO NOT EDIT BELOW THIS UNLESS YOU KNOW WHAT YOU ARE DOING !!!
var orgTitle = document.title;
var URL = document.location.href;
var isDom = URL.indexOf('forumwarz.com/domination') != -1;
var isIncit = URL.indexOf('forumwarz.com/incit') != -1;
var isAuc = URL.indexOf('forumwarz.com/auctions') != -1;
var isCharMe = URL.indexOf('forumwarz.com/characters/me') != -1;
var isIB = URL.indexOf('forumwarz.com/item_buildr') != -1;
var isFB = URL.indexOf('forumwarz.com/forum_buildr') != -1;
var fCD;
var type = ['day','hour','minute','second'];
if (debug) document.title = 'Script loaded...';
if (debug) var debugStr = 'Debug started.';
else var debugStr = 'Enable debugging, jackass';
if ( (isDom && trackDomination) || (isIncit && trackIncit) || (isAuc && trackAuctions) ||
(isCharMe && trackVisits) || (isIB && trackItemBuildr) || (isFB && trackForumBuildr) ){
debugAdd('Page trackable. Loading CD check.',false);
checkForCountdown();
}
function checkForCountdown(){
if (document.getElementById('countdown') != null){
debugAdd('Found CD element. Entering main',false);
main(); //countdown element is not empty. enter main
} else if (checkFinished()) {
finished();
return;
} else {
debugAdd('Element not ready. Looping...',true);
setTimeout('checkForCountdown()', 1000); //else loop
}
}
//our main function that calls itself (loop)
function main() {
if (document.getElementById('countdown') == null){
if (isAuc){ //only auctions lose their element
debugAdd('Auction closed. Exiting.',false);
finished();
return; //just leave. don't loop
}
debugAdd('Element disappeared... Loop til found.',true);
document.title=orgTitle;
setTimeout('main()',1000); //keep retrying in a new thread
return; //exit this thread
} else if (document.getElementById('countdown').childNodes.length == 0) {
debugAdd('No children. Having secks again...',true);
setTimeout('main()',1000); //keep retrying in a new thread
return; //exit this thread
}
debugAdd('Entered main successfully.',true);
fCD = document.getElementById('countdown').firstChild.nodeValue; //full countdown
debugAdd('Set fCD.',true);
var newTitle = ''; //start out new title variable as empty
if (isIncit){ //INCIT specific code for voting page notify!
if (fCD.indexOf('ends') != -1) newTitle = 'VOTING!' + spacer;
}
var hasFinished = false;
var t = getCdTextSplit();
if ( (t[0]==0&&t[1]==0&&t[2]==0&&t[3]==1) )
hasFinished = true;
if ( (isAuc && hasFinished) ||
(isFB && hasFinished && allowEnd) ||
(isIB && hasFinished && allowEnd) ||
(isDom && hasFinished && allowEnd) ||
(isCharMe && hasFinished && allowEnd) ){
finished(); //post our ending title
return; //leave without looping
}
if (useShort || useExShort || useZeros){
debugAdd('Running getCdTextSplit.',true);
var cdTextSplit = getCdTextSplit();
for (i=0;i<cdTextSplit.size();i++){
if ( (cdTextSplit[i] > 0 || useZeros) && (cdTextSplit[i] > 0 || !useExShort) ||
(i==3 && cdTextSplit[3] == 0 && newTitle != '') ){ //add 0 seconds to non-empty title
newTitle += cdTextSplit[i] + type[i].substr(0,1) + spacer;
}
if (cdTextSplit[i] > 0 && useExShort) break; //break loop after first non-zero
}
} else {
debugAdd('Fallback. Failed to get times.',true);
newTitle=fCD; //no match. use full countdown string
}
if (isIncit && trackIncit){ //INCIT specific code
debugAdd('INCIT Shit...',true);
var submissions = document.getElementById('submissions_received');
if (submissions!=undefined){ //for when it's not loaded yet
submissions = submissions.innerHTML.split(' ',1); //first chars (number)
if (submissions[0] > 0){
newTitle += submissions[0] + 'sub' + spacer; //append number + 'sub' to new title
}
debugAdd('Finished sub add code.',true);
}
var links = document.getElementsByTagName('a'); //grab all links
var ass = '0'; //initialize 'ass'
for(i=0;i<60;i++){ //should be the 47th link, but we will search this range if links change
if (links[i].text.indexOf('Assholes Online') != -1){ //find 'Assholes Online' link text
ass = links[i].text.split(' ',1); //grab first chars (number)
newTitle += spacer + ass[0] + 'ass' + spacer; //append number + 'ass' to new title
break; //exit loop. we only need one match. I got two for some reason...
}
}
debugAdd('Finished ass add code.',true);
}
if (!newTitle) newTitle = '...'; //Opera defaults to URL if the title is empty... big nono there.
document.title=newTitle; //finally, set the new title
debugAdd('Title set. Looping...',true);
setTimeout('main()', 1000); //loop main with delay
}
function getCdTextSplit(){
var offset;
var cdTextSplit = new Array(4);
for (i=0;i<type.size();i++){
offset = fCD.indexOf(type[i]);
cdTextSplit[i] = offset != -1 ? fCD.substr(fCD.indexOf('',offset-3), 2).strip(' ') : 0;
}
return cdTextSplit;
}
function debugAdd(str,verbose){
if (debug && (!verbose || debugVerbose)) debugStr += '\n' + str;
}
function dbg(){
alert(debugStr);
}
function finished(){
if (isAuc)
document.title='Auction closed!';
else if (isDom)
document.title='Dom round over!';
else if (isFB)
document.title='FB ended!';
else if (isIB)
document.title='IB ended!';
else if (isIB)
document.title='New visits & gifts!';
}
function checkFinished(){
if (!isAuc) return false; //only auctions can "start" in finished state.
if (document.getElementById('remaining') != null){
var text = document.getElementById('remaining').firstChild.nodeValue;
if (text.indexOf('This auction is closed.') != -1){
debugAdd('Auction finished. Exit.',false);
return true;
} else {
debugAdd('Auction NOT finished. Continue,',false);
return false;
}
} else {
debugAdd("ERROR: You shouldn't see this",false);
return false;
}
}