<%#
 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 style=color:green>"+result.ping+"</b> ms" : "<b style=color:red><%:Test failed%></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 style=color:green>"+result.ping+"</b> ms" : "<b style=color:red><%:Test failed%></b>");
			}
		);
	}
	//]]>
</script>
