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

<script type="text/javascript">
	//<![CDATA[
	var pings = document.getElementsByClassName('ping');
	for(var i = 0; i < pings.length; i++) {
		XHR.get('<%=luci.dispatcher.build_url("admin", "services", "clash", "ping")%>',{
		
				index: i,
				domain: pings[i].getAttribute("hint")
			},
			function(x, result) {
			
				XHR.get('<%=luci.dispatcher.build_url("admin", "services", "clash", "ping_check")%>', null, function(x, status) {
					if ( x && x.status == 200 ) {
						if(status.ping_enable==1){
							pings[result.index].innerHTML = (result.ping ? '<b><font color="green">'+result.ping+'</font></b> ms' : '<b><font color="red"><%:Error%></font></b>');
						}else{
							pings[result.index].innerHTML = result.ping ? '<b><font color="red"><%:DISABLED%></font></b>' : '<b><font color="red"><%:DISABLED%></font></b>';
						}
					}
				})
			}
		);
		
		XHR.poll(15,'<%=luci.dispatcher.build_url("admin", "services", "clash", "ping")%>',{
		
				index: i,
				domain: pings[i].getAttribute("hint")
			},
			function(x, result) {
			
				XHR.poll(15,'<%=luci.dispatcher.build_url("admin", "services", "clash", "ping_check")%>', null, function(x, status) {
					if ( x && x.status == 200 ) {
						if(status.ping_enable==1){
							pings[result.index].innerHTML = (result.ping ? '<b><font color="green">'+result.ping+'</font></b> ms' : '<b><font color="red"><%:Error%></font></b>');
						}else{
							pings[result.index].innerHTML = result.ping ? '<b><font color="red"><%:DISABLED%></font></b>' : '<b><font color="red"><%:DISABLED%></font></b>';
						}
					}
				})
			}
		);
	}
	//]]>
</script>
 
