משתמש:גאון הירדן/טיימר.js
מראה
לתשומת ליבך: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.
- פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
- גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
- אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
if (( mw.config.get( 'wgPageName' )=="עמוד_ראשי")&&(confirm('לאפס מונה?'))){
var startTime = Math.floor(Date.now() / 1000); //Get the starting time (right now) in seconds
console.log(startTime);
$.cookie("loginDate", startTime, {
path: "https://www.hamichlol.org.il/"
});
}else{
var startTime = $.cookie("loginDate");
console.log(startTime);
localStorage.setItem("startTime", startTime); // Store it if I want to restart the timer on the next page
}
$('<div id= "clock-timer"></div>').prependTo('#bodyContent');
function startTimeCounter() {
var now = Math.floor(Date.now() / 1000); // get the time now
var diff = now - startTime; // diff in seconds between now and start
var h = Math.floor(diff /3600 );//מספר הדקות בשעה
var m = Math.floor((diff / 60)%60); // get minutes value (quotient of diff)
var s = Math.floor(diff % 60); // get seconds value (remainder of diff)
h = checkTime(h); // add a leading zero if it's single digit
m = checkTime(m); // add a leading zero if it's single digit
s = checkTime(s); // add a leading zero if it's single digit
document.getElementById("clock-timer").innerHTML = h + ':' + m + ":" + s; // update the element where the timer will appear
var t = setTimeout(startTimeCounter, 500); // set a timeout to update the timer
}
function checkTime(i) {
if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10
return i;
}
startTimeCounter();
/*
mw.loader.load( '/w/index.php?title=User:גאון הירדן/טיימר.css&action=raw&ctype=text/css', 'text/css' );
var clockDivMain = '<h1>זמן כולל</h1>'
+'<div id="clockdiv">'
+'<div>'
+'<span class="seconds"></span>'
+'<div class="smalltext">שניות</div>'
+' </div>'
+' <div>'
+' <span class="minutes"></span>'
+'<div class="smalltext">דקות</div>'
+'</div>'
+'<div>'
+' <span class="hours"></span>'
+'<div class="smalltext">שעות</div>'
+' </div>'
+' <div>'
+' <span class="days"></span>'
+'<div class="smalltext">ימים</div>'
+'</div>'
+'</div>';
$('#bodyContent').append(clockDivMain);
function getTimeRemaining(endtime) {
const total = Date.parse(endtime) - Date.parse(new Date());
const seconds = Math.floor((total / 1000) % 60);
const minutes = Math.floor((total / 1000 / 60) % 60);
const hours = Math.floor((total / (1000 * 60 * 60)) % 24);
const days = Math.floor(total / (1000 * 60 * 60 * 24));
return {
total,
days,
hours,
minutes,
seconds
};
}
function initializeClock(id, endtime) {
const clock = document.getElementById(id);
const daysSpan = clock.querySelector('.days');
const hoursSpan = clock.querySelector('.hours');
const minutesSpan = clock.querySelector('.minutes');
const secondsSpan = clock.querySelector('.seconds');
function updateClock() {
const t = getTimeRemaining(endtime);
daysSpan.innerHTML = t.days;
hoursSpan.innerHTML = ('0' + t.hours).slice(-2);
minutesSpan.innerHTML = ('0' + t.minutes).slice(-2);
secondsSpan.innerHTML = ('0' + t.seconds).slice(-2);
if (t.total <= 0) {
clearInterval(timeinterval);
}
}
updateClock();
const timeinterval = setInterval(updateClock, 1000);
}
const deadline = new Date(Date.parse(new Date()) + 15 * 24 * 60 * 60 * 1000);
initializeClock('clockdiv', deadline);
*/