<%+header%>
<script>
function runscript(url) {
	var script = document.createElement('script');  
	script.setAttribute('src', url);
	document.getElementsByTagName('head')[0].appendChild(script);  
}
function onSetTime(s) {
	if(s == '0') {
		document.getElementById('dvMsg').innerHTML = "<%:Time synchronization successful %>";
		runscript( '/cgi-bin/luci/admin/oplus/ontime_load_sys_time/' );
	}	
}
function onLoadSysTime(t, tz) {
	document.getElementById('spSysTz').innerHTML = tz;
}
function formatDate(date) {
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份是从0开始的
  const day = String(date.getDate()).padStart(2, '0');
  const hours = String(date.getHours()).padStart(2, '0');
  const minutes = String(date.getMinutes()).padStart(2, '0');
  const seconds = String(date.getSeconds()).padStart(2, '0');
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}

function do_submit() {
	runscript( '/cgi-bin/luci/admin/oplus/ontime_set_time/?time='+ encodeURIComponent(formatDate(new Date())) +
		"&zonename="+ encodeURIComponent(document.getElementById('zonename').value) );
}
</script>

<br><br>
<b><%:This tool is used to synchronize time and timezone with browser %></b><br><br>
<%:Most OpenWrt devices have a built-in time synchronization function, but it may not perfectly work, and timezone may be incorrect. %><br>
<%:It will cause issues if time or timezone is incorrect. It is recommended to use this tool to synchronize time and timezone. %>
<br><br>
<center>
<div id="dvMsg" style="color:#008800"></div>
<br>
<table>
	<tr style="height: 50px;">
		<td> <%:Time in Browser %> : </td>
		<td> <input type="text" id="time" value="" readonly /> </td>
	</tr>
	<tr style="height: 50px;">
		<td> <%:Time Zone in Browser %> : </td>
		<td>  <input type="text" id="zonename" value="" readonly /> </td>
	</tr>
	<tr style="height: 50px;">
		<td> <%:Time Zone in System %> : </td>
		<td> <span id="spSysTz"></span> </td>
	</tr>
</table>

<br>
<input type="button" style="background-color: #0055ff; color: #fff; width:100px; height: 40px;" value="<%:Synchronize %>" onclick="do_submit();" />

<br><br>
<a href="http://www.wiwiz.com/pinpinwifi/oplus/help.htm" target="_blank"><%:Docs %></a>
<br><br>
Copyright &copy; 2025-<script>document.write(new Date().getFullYear());</script> <a href="http://www.wiwiz.com/pinpinwifi" target='_blank'>www.PinPinWiFi.com</a>. All rights reserved.
<br>
<%: We reserve the right to pursue legal responsibility for any unauthorized copying, distribution, cracking, reverse engineering, unauthorized use, etc. %>
<br>
</center>

<script>
	setInterval(function() {
		document.getElementById('time').value = formatDate(new Date());
	}, 1000);
	document.getElementById('time').value = formatDate(new Date());

	var tz = "";
	if(typeof Intl == "undefined") {
		tz = "UTC";
	} else {
		tz = new Intl.DateTimeFormat().resolvedOptions().timeZone;
	}
	document.getElementById('zonename').value = tz;

	runscript( '/cgi-bin/luci/admin/oplus/ontime_load_sys_time/' );
</script>

<%+footer%>