From Dark and Darker Wiki

(Changing scope of a countDownDate var)
No edit summary
 
(18 intermediate revisions by 2 users not shown)
Line 6: Line 6:
     return setInterval(func, interval);
     return setInterval(func, interval);
}
}
var id = "<!--{$uniqueId|default:'timer'|escape:'html'}-->"
var <!--{$uniqueId|default:'timer'|escape:'html'}--> = setIntOnStart( _ => {
var x = setIntOnStart( _ => {
    let id = "<!--{$uniqueId|default:'timer'|escape:'html'}-->";
     var countDownDate = new Date('<!--{$date|escape:'quotes'}-->').getTime();
    let timezoneOffset = new Date().getTimezoneOffset()*60*1000;
     var now = new Date().getTime();
     let countDownDate = new Date('<!--{$date|escape:'quotes'}-->').getTime();
     var distance = countDownDate - now;
     let now = new Date().getTime() + timezoneOffset;
     var days = Math.floor(distance / (1000 * 60 * 60 * 24));
     let distance = countDownDate - now;
     var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
     let days = Math.floor(distance / (1000 * 60 * 60 * 24));
     var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
     let hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
     var seconds = Math.floor((distance % (1000 * 60)) / 1000);
     let minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
     let seconds = Math.floor((distance % (1000 * 60)) / 1000);


     document.getElementById(id).innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s ";
     document.getElementById(id).innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s ";


     if (distance < 0) {
     if (distance < 0) {
         clearInterval(x);
         clearInterval(<!--{$uniqueId|default:'timer'|escape:'html'}-->);
         document.getElementById(id).innerHTML = "LIVE NOW";
         document.getElementById(id).innerHTML = "ENDED";
     }
     }
}, 1000);
}, 1000);
Line 34: Line 35:
**Example:<code>2024-12-31 23:59:59</code>
**Example:<code>2024-12-31 23:59:59</code>


==Example 1==
<pre>{{#widget:Countdown|uniqueId=A|date=2025-08-26 23:59:59}}</pre>
{{#widget:Countdown|uniqueId=A|date=2025-08-26 23:59:59}}


==Example 1==
<pre>{{#widget:Countdown|uniqueId=A|date=2024-08-26 23:59:59}}</pre>
{{#widget:Countdown|uniqueId=A|date=2024-08-26 23:59:59}}
==Example 2==
==Example 2==
<pre>{{#widget:Countdown|uniqueId=B|date=2024-08-25 23:59:59}}</pre>
<pre>{{#widget:Countdown|uniqueId=B|date=2024-12-10 20:00:00}}</pre>
{{#widget:Countdown|uniqueId=B|date=2024-08-25 23:59:59}}
{{#widget:Countdown|uniqueId=B|date=2024-12-10 20:00:00}}
 
==Example 3==
==Example 3==
<pre>{{#widget:Countdown|uniqueId=C|date=2024-08-24 23:59:59}}</pre>
<pre>{{#widget:Countdown|uniqueId=C|date=2024-08-24 23:59:59}}</pre>
{{#widget:Countdown|uniqueId=C|date=2024-08-24 23:59:59}}
{{#widget:Countdown|uniqueId=C|date=2024-08-24 23:59:59}}
</noinclude>
</noinclude>

Latest revision as of 18:44, 10 December 2024

Parameters

uniqueId
  • Determines element id name
  • Name needs to be unique if multiple widgets are to be displayed on the same page.
  • Default: timer
date
  • String of text indicating a date and time.
    • Example:2024-12-31 23:59:59

Example 1

{{#widget:Countdown|uniqueId=A|date=2025-08-26 23:59:59}}

Example 2

{{#widget:Countdown|uniqueId=B|date=2024-12-10 20:00:00}}

Example 3

{{#widget:Countdown|uniqueId=C|date=2024-08-24 23:59:59}}