
<%
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('<%=dsp.build_url("admin", "services", "clash", "ping")%>', {
				index: i,
				domain: pings[i].getAttribute("hint")
			},
			function(x, result) {
					if (result.ping < 500) {
					pings[result.index].innerHTML = (result.ping ? "<b><font color='#ee1010'>"+result.ping+"</font></b> ms" : "<b><font color=red><%:Error%></font></b>");
					}
					if (result.ping < 200){
					pings[result.index].innerHTML = (result.ping ? "<b><font color='#7acc03'>"+result.ping+"</font></b> ms" : "<b><font color=red><%:Error%></font></b>");
					}
					if (result.ping < 100){
					pings[result.index].innerHTML = (result.ping ? "<b><font color='#007e1a'>"+result.ping+"</font></b> ms" : "<b><font color=red><%:Error%></font></b>");
					}
					
			}
		);
		XHR.poll(20,'<%=dsp.build_url("admin", "services", "clash", "ping")%>',{
				index: i,
				domain: pings[i].getAttribute("hint")
			},
			function(x, result) {
					if (result.ping < 500) {
					pings[result.index].innerHTML = (result.ping ? "<b><font color='#ee1010'>"+result.ping+"</font></b> ms" : "<b><font color=red><%:Error%></font></b>");
					}
					if (result.ping < 200){
					pings[result.index].innerHTML = (result.ping ? "<b><font color='#7acc03'>"+result.ping+"</font></b> ms" : "<b><font color=red><%:Error%></font></b>");
					}
					if (result.ping < 100){
					pings[result.index].innerHTML = (result.ping ? "<b><font color='#007e1a'>"+result.ping+"</font></b> ms" : "<b><font color=red><%:Error%></font></b>");
					}
					
			}
		);
	}
	//]]>
</script>
 
