Furry stuff, oekaki stuff, and other stuff.
You are not logged in.
I don't think I've made a topic about this yet here...8}
Recently I've tried adding a java timer code (which I found online~) to the bbs pages to allow my members to see how long they've been drawing so they won't break the time rule.
The code works on the shipainter boards and oekakibbs, but once the applet loads in the paintbbs and notebbs boards, the timer code will stop working. Is there any tweak I can do to make this work properly, or would the timer simply not work either way?
Here's the timer code:
In the <head> tag: (I have it in header.php)
---------
<script language="JavaScript">
<!-- Hide from old browsers
var hour = "0"
var min = "00"
var sec = "0"
function timer(){
if ((min < 10) && (min != "00")){
dismin = "0" + min
}
else{
dismin = min
}
dissec = (sec < 10) ? sec = "0" + sec : sec
document.timer.counter.value = hour + ":" + dismin + ":" + dissec
if (sec < 59){
sec++
}
else{
sec = "0"
min++
if (min > 59){
min = "00"
hour++
}
}
window.setTimeout("timer()",1000)
}
// -->
</script>
---------
Below the <body> tag: (I have it in shiBBS.php, oekakiBBS.php and noteBBS.php [didn't bother with paintBBS since it won't work in note])
---------
<body onLoad="timer()">
Time on page:
<form name="timer">
<input type=text value="" class="ptxtinput" name="counter" size=8>
</form><br>
---------
It won't work on any BBS if I put the onload timer bit in the body tag from the header page, but again it does work with the code above in the Shipainter and oekakiBBS boards.
The codes are in place in this board if you'd like to see: http://www.sutaro.com/oekaki/
Sorry if I explained any of this badly. I'm just trying to make it easier for my members to follow the rules..and unfortunately failing at it.
Offline
I'm afraid this is a lot more complicated than you might think.
See, the Shi-Chan applets have some kind of JavaScript-handling bug that breaks all JavaScript support in browsers. This is why the "Maximize" button sometimes doesn't work until you push it a couple times. That means if you start a timer, it will stop working, and has to be restarted after the applet initializes. In other words, you have to find a way to get a stopped script to start working again. This is hard, because JavaScript is not multi-threaded. Once it stops, it's dead unless you force a re-initialization with an "onclick" or "mouseover" event.
To make matters worse, "onclick" and "mouseover" events do not work with applets. A web browser can't tell if you're clicking on an applet or not!
There is a solution, however: a custom thread system, and mouseover events on the <body> tag.
Insert this into the HTML for each paint program (or even better, copy to a "timer.js" file, in the same fashion as "Poteto.js"):
<script type="text/javascript"> var timer_start = 0; // Set when counter started var timer_delta = 0; // Time since last update var timer_id = 0; /* int|string toZeros(int) Returns sprintf("%d2", int)... ...because JavaScript sucks. */ function toZeros(num) { if (num < 10) { return ("0" + num); } else { return (num); } } /* int getEpoch(void) Returns the current UNIX epoch, in seconds */ function getEpoch() { var now = new Date(); return (now.valueOf() / 1000); } /* void timer_start(elementID) Starts one instance of timer() for element ID. Required due to JavaScript complaince issue with Shi-chan oekaki applets */ function startTimer(id) { // Timer set? Set only once. if (timer_start < 1) { timer_start = getEpoch(); } // Test if timer has failed/stopped (due to JavaScript error) // Delta should be no less than 2 seconds off if ((getEpoch() - timer_start) > (timer_delta + 2)) { // Fail! Continue timer timer_id = 0; } // Start timer if not counting if (timer_id == 0) { if (document.getElementById && document.getElementById(id)) { timer_id = Math.round(Math.random() * 100000) + 1; picTimer(id, timer_id); } } } /* void picTimer(elementID) Timer for oekaki applets. Sets string value via DOM elementID. */ function picTimer(id, thread) { // Update delta timer_delta = getEpoch() - timer_start; // Process fields var sec = Math.floor (timer_delta % 60); var min = Math.floor (timer_delta / 60 % 60); var hour = Math.floor (timer_delta / 3600 % 60); // Update HTML // Get new ID reference every time var new_id = document.getElementById(id); new_id.value = toZeros(hour) + ":" + toZeros(min) + ":" + toZeros(sec); // Recursive call every second. if (thread == timer_id) { window.setTimeout("picTimer('" + id + "', " + thread + ")", 100); } } </script>
Now, add this to the body tag:
<body onload="startTimer('my_timer');" onmouseover="startTimer('my_timer');">
Better yet, add it to the applet's <div> container, too:
<div style="text-align: center;" onmouseover="startTimer('my_timer');"> <applet id="paintbbs" (applet crap here)...
Finally, add this underneath the maximize button (or somewhere right under the applet):
<p style="text-align: center;"> Time on page: <input type="text" id="my_timer" value="00:00:00" class="ptxtinput" size="8" /> </p>
What happens is that the timer will start, then when the applet initializes, the timer will stop. Move the mouse cursor anywhere in the web page, and the timer will start up again (and stay working).
I tell you, the Internet is a real pain in the rear. JavaScript should be set on fire.
Offline
Whoops forgot to reply!
The timer works perfectly now, I appreciate your help on this a lot. I've been struggling with it for over a year and searching for different types of timers that would work, heh.
Offline