<%#
 Copyright 2018-2019 Lienol <lawlienol@gmail.com>
 Licensed to the public under the Apache License 2.0.
-%>

<%
local dsp = require "luci.dispatcher"
-%>

<script type="text/javascript">
	//<![CDATA[
	var pings = document.getElementsByClassName('pingtime');
	for(var i = 0; i < pings.length; i++) {
		XHR.get('<%=dsp.build_url("admin", "services", "openclash", "ping")%>', {
				index: i,
				domain: pings[i].getAttribute("hint")
			},
			function(x, result) {
				pings[result.index].innerHTML = (result.ping ? "<b><font color=green>"+result.ping+"</font></b> ms" : "<b><font color=red><%:Test failed%></font></b>");
			}
		);
		XHR.poll(10,'<%=dsp.build_url("admin", "services", "openclash", "ping")%>',{
				index: i,
				domain: pings[i].getAttribute("hint")
			},
			function(x, result) {
				pings[result.index].innerHTML = (result.ping ? "<b><font color=green>"+result.ping+"</font></b> ms" : "<b><font color=red><%:Test failed%></font></b>");
			}
		);
	}
	//]]>
</script>