43 lines
1.3 KiB
HTML
43 lines
1.3 KiB
HTML
{{ $mode := .Get 0 }}{{ $opt1 := .Get 1 }}{{ $opt2 := .Get 2 }}
|
|
|
|
{{ $img_on := ( printf "%s%s" $.Page.Site.BaseURL "img/on-off/switch-on-icon_smal.png" )}}
|
|
{{ $img_off := ( printf "%s%s" $.Page.Site.BaseURL "img/on-off/switch-off-icon_smal.png" )}}
|
|
|
|
{{ if eq $mode "on" }}
|
|
<img src="{{ $img_on }}" alt="On">
|
|
{{ else if eq $mode "off"}}
|
|
<img src="{{ $img_off }}" alt="Off">
|
|
{{ else if eq $mode "imgping" }}
|
|
{{ with $opt1 }}
|
|
{{ $id := md5 $opt1 }}
|
|
{{ if eq $opt2 "on" }}
|
|
<img id={{ $id }} src="{{ $img_on }}" alt="On">
|
|
{{ else }}
|
|
<img id={{ $id }} src="{{ $img_off }}" alt="Off">
|
|
{{ end }}
|
|
<script language="JavaScript">
|
|
|
|
function imgping(id,url){
|
|
while (true) {
|
|
function Sleep(milliseconds) {
|
|
return new Promise(resolve => setTimeout(resolve, milliseconds));
|
|
}
|
|
var imgping = new Image();
|
|
imgping.src = url;
|
|
if(imgping.height>0){
|
|
document.getElementById(id).outerHTML ='<img src="{{ $img_on }}" alt="On">';
|
|
} else {
|
|
document.getElementById(id).outerHTML ='<img src="{{ $img_off }}" alt="Off">';
|
|
}
|
|
Sleep(15000);
|
|
}
|
|
}
|
|
imgping({{ $id }},{{ $opt1 }});
|
|
</script>
|
|
{{ else }}
|
|
imgping [URL to image] [default on/off]
|
|
{{ end }}
|
|
{{ else }}
|
|
???
|
|
{{ end }}
|