46 lines
1.3 KiB
HTML
46 lines
1.3 KiB
HTML
<!DOCTYPE html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
|
<meta name="viewport"
|
|
content="width=device-width, initial-scale=1, user-scalable=yes">
|
|
<meta name="author" content="acdw">
|
|
<title>moon</title>
|
|
<link rel="stylesheet" type="text/css" href="style.css" />
|
|
<script src="suncalc.js" type="text/javascript"> </script>
|
|
</head>
|
|
<body>
|
|
<p>
|
|
The moon is <span id="phase"></span> tonight, long live the moon.
|
|
</p>
|
|
<script>
|
|
function phaseStr(phase) {
|
|
if (phase == 0) {
|
|
return "new";
|
|
} else if (phase < 0.25) {
|
|
return "a waxing crescent";
|
|
} else if (phase == 0.25) {
|
|
return "at first quarter";
|
|
} else if (phase < 0.5) {
|
|
return "a waxing gibbous";
|
|
} else if (phase == 0.5) {
|
|
return "full";
|
|
} else if (phase < 0.75) {
|
|
return "a waning gibbous";
|
|
} else if (phase == 0.75) {
|
|
return "at last quarter";
|
|
} else if (phase < 1) {
|
|
return "a waning crescent";
|
|
}
|
|
}
|
|
|
|
let phase = phaseStr(SunCalc.getMoonIllumination(new Date()).phase);
|
|
let moondesc = document.getElementById("phase");
|
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
moondesc.innerHTML = phase;
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|