Not logged in. · Lost password · Register
Forum: Skins RSS
JavaScript stuff
Time-checking in dynamic skins
duncanbeevers #1
Member since Dec 2005 · 3 posts
Group memberships: Members
Show profile · Link to this post
Looked over Fred's and Gugenheim skins and noticed the time-detection is a bit janky.  For the skin / functionality I'm working on, I decided to just go ahead and rework.  Apologies for the language modifications, but I was having a hard time with sekund.

<script language="JavaScript" type="text/JavaScript">
window.onload = begin_progress_update;
function begin_progress_update(){
    var current_time = new Date();
    timeout_time = current_time.valueOf() + remaining_time * 1000;
    countDown();
}

//Modified code from    Brett Taylor ([email protected])
//    Dynamic Drive for NS4, NS6+ (http://www.dynamicdrive.com)
//    Fred ([email protected])

//configure refresh interval (in seconds)
var elapsed_minutes    = <#SongPositionMin>;
var elapsed_seconds    = <#SongPositionSec>;
var remaining_minutes    = <#SongRemainMin>;
var remaining_seconds    = <#SongRemainSec>;
var progress  = elapsed_minutes * 60 + elapsed_seconds;
var status      = <#status on_play=0 on_stop=1 on_pause=2>;
var duration  = <#SongLengthMin> * 60 + <#SongLengthSec>;
var remaining_time    = remaining_minutes * 60 + remaining_seconds;

var timeout_time; // defined by begin_progress_update

function countDown() {
    var current_time = new Date();
    remaining_time = Math.floor((timeout_time - current_time.valueOf()) / 1000);
    if (status==0) {
  remaining_seconds = remaining_time % 60;
  remaining_minutes = Math.floor((remaining_time - remaining_seconds) / 60);
  var elapsed_time    = duration - remaining_time;
  elapsed_seconds    = elapsed_time % 60;
  elapsed_minutes    = Math.floor((elapsed_time - elapsed_seconds) / 60);
  progress  = elapsed_minutes * 60 + elapsed_seconds;
    }

    if (remaining_time < 0){
  window.location.href = lokace;
  return;
    }

    if (String(elapsed_seconds).length < 2) { elapsed_seconds = "0" + elapsed_seconds; }
    if (String(remaining_seconds).length < 2) { remaining_seconds = "0" + remaining_seconds; }
    var time_update_string = elapsed_minutes + ":" + elapsed_seconds + " / -" + remaining_minutes + ":" + remaining_seconds + " (<#SongLengthMin>:<#SongLengthSec>)";
    if (document.all) { //if IE 4+
  document.all.countDownText.innerText = time_remaining_string;
    }
    else if (document.getElementById) { //else if NS6+
  document.getElementById("countDownText").innerHTML= time_update_string;
    }
    updatePos();

    counter=setTimeout("countDown()", 200);
}

function updatePos() {
    var Position = parseInt(100 * progress / duration);

    if (isNaN(Position)) {
  Position = 1;
    }

    // define the width of the left side
    // of the progress bar
    if (Position == 0) {
  Position = 1;
    }
    // determine which procent field should
    // receive the percent text
    var procent1_text = "";
    var procent2_text = "";
    if (Position > 50) {
  var procent1_text = Position + "%";
    }
    else {
  var procent2_text = Position + "%";
    }

    if (document.all) {
  //if IE 4+
  progressBarLeft.width = Position + "%";
  procent1.innerText = procent1_text;
  procent2.innerText = procent2_text;
    }
    else if (document.getElementById) {
  //else if NS6+
  document.getElementById("progressBarLeft").width = Position + "%";
  document.getElementById("procent1").innerHTML= procent1_text;
  document.getElementById("procent2").innerHTML= procent2_text;
    }

    if (status == 1) {
  Position = 0;
    }
}
</script>

You should be able to essentially overwrite Fred's tempates/fPlayer.html second <script> section with this code and achieve the same functionality, but with more accurate time-tracking.  Don't chop without looking, I wrote this for my skin, not Fred's.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Page created in 189.4 ms (90 ms) · 37 database queries in 83.7 ms
Current time: 2018-07-17, 09:37:44 (UTC +00:00)