View difference between Paste ID: 1D9QjKD4 and
SHOW:
|
|
- or go back to the newest paste.
1 | - | |
1 | + | // Opera UserJS - Countdown script for forumwarz.com |
2 | // This will place the countdown timer into the title | |
3 | // Author: TT | |
4 | // v1.4.0 | |
5 | ||
6 | //set these variables for the 'options' | |
7 | var useShort=true; //set to false if you prefer long string as title | |
8 | var useExShort=false; //only uses biggest value (e.g. days only when at least one remains). trumps useShort. | |
9 | var spacer=''; //default is a 'nothing' for the spacer. use ' ' for a space | |
10 | var useZeros=false; //show 0 days/hours/minutes as '0' instead of excluding them | |
11 | var trackIncit=true; | |
12 | var trackDomination=true; | |
13 | var trackAuctions=true; | |
14 | var trackVisits=true; // track time until visits reload (also deliveries) on /character/me | |
15 | var trackItemBuildr=true; | |
16 | var trackForumBuildr=true; | |
17 | var debug=false; // if there is a problem, you can look at the debug log with javascript:dbg() in address bar | |
18 | var debugVerbose=false; // use with caution as this stores strings that are used in loops and can eat memory | |
19 | ||
20 | // !!! DO NOT EDIT BELOW THIS UNLESS YOU KNOW WHAT YOU ARE DOING !!! | |
21 | ||
22 | var orgTitle = document.title; | |
23 | var URL = document.location.href; | |
24 | var isDom = URL.indexOf('forumwarz.com/domination') != -1; | |
25 | var isIncit = URL.indexOf('forumwarz.com/incit') != -1; | |
26 | var isAuc = URL.indexOf('forumwarz.com/auctions') != -1; | |
27 | var isCharMe = URL.indexOf('forumwarz.com/characters/me') != -1; | |
28 | var isIB = URL.indexOf('forumwarz.com/item_buildr') != -1; | |
29 | var isFB = URL.indexOf('forumwarz.com/forum_buildr') != -1; | |
30 | var tArray = new Array(4); | |
31 | var fCD; | |
32 | var type = ['day','hour','minute','second']; | |
33 | var source; | |
34 | ||
35 | if (debug) document.title = 'Script loaded...'; | |
36 | if (debug) var debugStr = 'Debug started.'; | |
37 | else var debugStr = 'Enable debugging jackass'; | |
38 | //var counts = 1; | |
39 | ||
40 | window.opera.addEventListener( | |
41 | 'afterscript', //we definitely want scripts loaded first | |
42 | function (e) { //only enter main if we are on a proper page and the countdown script loaded | |
43 | source = e.element.getAttribute('src'); | |
44 | if (source != null){ | |
45 | if( source.indexOf('countdown.js') != -1 && ( | |
46 | (isDom && trackDomination) || | |
47 | (isIncit && trackIncit) || | |
48 | (isAuc && trackAuctions) || | |
49 | (isCharMe && trackVisits) || | |
50 | (isIB && trackItemBuildr) || | |
51 | (isFB && trackForumBuildr) | |
52 | )){ | |
53 | debugAdd('CD script loaded. Loading CD check.',false); | |
54 | setTimeout('checkForCountdown()', 1000); //give it 1 second for safety | |
55 | } | |
56 | } | |
57 | }, | |
58 | false | |
59 | ); | |
60 | ||
61 | ||
62 | function checkForCountdown(){ //TODO add end of timer check here or maybe main() | |
63 | if(document.getElementById('countdown') != null){ | |
64 | debugAdd('Found CD element. Entering main',false); | |
65 | main(); //countdown element is not empty. enter main | |
66 | }else{ | |
67 | debugAdd('Element not ready. Looping...',true); | |
68 | setTimeout('checkForCountdown()', 1000); //else loop | |
69 | } | |
70 | } | |
71 | ||
72 | ||
73 | //our main function that calls itself (loop) | |
74 | function main() { | |
75 | if(document.getElementById('countdown') == null){ | |
76 | debugAdd('Element disappeared... Loop til found.',true); | |
77 | document.title=orgTitle; | |
78 | setTimeout('main()',1000); //keep retrying in a new thread | |
79 | return; //exit this thread | |
80 | } else if (document.getElementById('countdown').childNodes.length == 0) { | |
81 | debugAdd('No children. Having secks again...',true); | |
82 | // alert('caught ya bitch!'); | |
83 | setTimeout('main()',1000); //keep retrying in a new thread | |
84 | return; //exit this thread | |
85 | } | |
86 | debugAdd('Entered main successfully.',true); | |
87 | ||
88 | fCD = document.getElementById('countdown').firstChild.nodeValue; //full countdown | |
89 | debugAdd('Set fCD.',true); | |
90 | var newTitle = ''; //start out new title variable as empty | |
91 | ||
92 | if(isIncit && trackIncit){ //INCIT specific code for voting page notify! | |
93 | if(fCD.indexOf('ends') != -1) newTitle = 'VOTING!' + spacer; | |
94 | } | |
95 | ||
96 | if(useShort || useExShort || useZeros){ | |
97 | debugAdd('Running getTimes.',true); | |
98 | getTimes(); | |
99 | for (i=0;i<tArray.size();i++){ | |
100 | if ( (tArray[i] > 0 || useZeros) && (tArray[i] > 0 || !useExShort) ) newTitle += tArray[i] + type[i].substr(0,1) + spacer; | |
101 | if (tArray[i] > 0 && useExShort) break; //break loop after first non-zero | |
102 | } | |
103 | } else { | |
104 | debugAdd('Fallback. Failed to get times.',true); | |
105 | newTitle=fCD; //no match. use full countdown string | |
106 | } | |
107 | ||
108 | ||
109 | if(isIncit && trackIncit){ //INCIT specific code | |
110 | debugAdd('INCIT Shit...',true); | |
111 | var submissions = document.getElementById('submissions_received'); | |
112 | if(submissions!=undefined){ //for when it's not loaded yet | |
113 | submissions = submissions.innerHTML.split(' ',1); //first chars (number) | |
114 | if(submissions[0] > 0){ | |
115 | newTitle += submissions[0] + 'sub' + spacer; //append number + 'sub' to new title | |
116 | } | |
117 | debugAdd('Finished sub add code.',true); | |
118 | } | |
119 | ||
120 | var links = document.getElementsByTagName('a'); //grab all links | |
121 | var ass = '0'; //initialize 'ass' | |
122 | for(i=0;i<60;i++){ //should be the 47th link, but we will search this range if links change | |
123 | if (links[i].text.indexOf('Assholes Online') != -1){ //find 'Assholes Online' link text | |
124 | ass = links[i].text.split(' ',1); //grab first chars (number) | |
125 | newTitle += spacer + ass[0] + 'ass' + spacer; //append number + 'ass' to new title | |
126 | break; //exit loop. we only need one match. I got two for some reason... | |
127 | } | |
128 | } | |
129 | debugAdd('Finished ass add code.',true); | |
130 | } | |
131 | ||
132 | if (!newTitle) newTitle = '...'; //Opera defaults to URL if the title is empty... big nono there. | |
133 | document.title=newTitle; //finally, set the new title | |
134 | debugAdd('Title set. Looping...',true); | |
135 | setTimeout('main()', 1000); //loop main with delay | |
136 | } | |
137 | ||
138 | ||
139 | function getTimes(){ | |
140 | var offset; | |
141 | for (i=0;i<type.size();i++){ | |
142 | offset = fCD.indexOf(type[i]); | |
143 | tArray[i] = offset != -1 ? fCD.substr(fCD.indexOf('',offset-3), 2).strip(' ') : 0; | |
144 | } | |
145 | } | |
146 | ||
147 | function debugAdd(str,verbose){ | |
148 | if (debug && (!verbose || debugVerbose)) debugStr += '\n' + str; | |
149 | } | |
150 | ||
151 | function dbg(){ | |
152 | alert(debugStr); | |
153 | } |