// Opera UserJS - Countdown script for forumwarz.com
// This will place the countdown timer into the title
// Author: TT
// v1.4.0
//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. days only when at least one remains). 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 debug=false; // if there is a problem, you can look at the debug log with javascript:dbg() in address bar
var debugVerbose=false; // use with caution as this stores strings that are used in loops and can eat memory
// !!! 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 tArray = new Array(4);
var fCD;
var type = ['day','hour','minute','second'];
var source;
if (debug) document.title = 'Script loaded...';
if (debug) var debugStr = 'Debug started.';
else var debugStr = 'Enable debugging jackass';
//var counts = 1;
window.opera.addEventListener(
'afterscript', //we definitely want scripts loaded first
function (e) { //only enter main if we are on a proper page and the countdown script loaded
source = e.element.getAttribute('src');
if (source != null){
if( source.indexOf('countdown.js') != -1 && (
(isDom && trackDomination) ||
(isIncit && trackIncit) ||
(isAuc && trackAuctions) ||
(isCharMe && trackVisits) ||
(isIB && trackItemBuildr) ||
(isFB && trackForumBuildr)
)){
debugAdd('CD script loaded. Loading CD check.',false);
setTimeout('checkForCountdown()', 1000); //give it 1 second for safety
}
}
},
false
);
function checkForCountdown(){ //TODO add end of timer check here or maybe main()
if(document.getElementById('countdown') != null){
debugAdd('Found CD element. Entering main',false);
main(); //countdown element is not empty. enter main
}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){
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);
// alert('caught ya bitch!');
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 && trackIncit){ //INCIT specific code for voting page notify!
if(fCD.indexOf('ends') != -1) newTitle = 'VOTING!' + spacer;
}
if(useShort || useExShort || useZeros){
debugAdd('Running getTimes.',true);
getTimes();
for (i=0;i<tArray.size();i++){
if ( (tArray[i] > 0 || useZeros) && (tArray[i] > 0 || !useExShort) ) newTitle += tArray[i] + type[i].substr(0,1) + spacer;
if (tArray[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 getTimes(){
var offset;
for (i=0;i<type.size();i++){
offset = fCD.indexOf(type[i]);
tArray[i] = offset != -1 ? fCD.substr(fCD.indexOf('',offset-3), 2).strip(' ') : 0;
}
}
function debugAdd(str,verbose){
if (debug && (!verbose || debugVerbose)) debugStr += '\n' + str;
}
function dbg(){
alert(debugStr);
}