Created
October 17, 2018 14:17
-
-
Save pmurias/4ee170f8043efe4802c8e6fb55d6a187 to your computer and use it in GitHub Desktop.
A P6 DOM clock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Time: <span id="clockDisplay"></span> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $document = EVAL(:lang<JavaScript>, 'return document'); | |
my $window = EVAL(:lang<JavaScript>, 'return window'); | |
my $clockDisplay = $document.getElementById('clockDisplay'); | |
my $tick = 0; | |
$window.setInterval(-> { | |
$tick++; | |
while $clockDisplay<firstChild> { | |
$clockDisplay.removeChild($clockDisplay<firstChild>); | |
} | |
$clockDisplay<style><color> = $tick % 2 ?? 'red' !! 'green'; | |
my $now = DateTime.now; | |
$clockDisplay.appendChild($document.createTextNode(sprintf "%02d:%02d:%02d", $now.hour, $now.minute, $now.whole-second)); | |
CATCH {default {say $_.Str}} | |
}, 1000e0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment