openwrt_helloworld/luci-app-openclash/luasrc/view/openclash/switch_mode.htm
2024-09-25 05:44:37 +08:00

46 lines
1.5 KiB
HTML

<fieldset class="cbi-section">
<table width="100%">
<tr><td width="100%" colspan="4">
<p align="center" id="switch_mode">
<%:Collecting data...%>
</p>
</td></tr>
</table>
</fieldset>
<script type="text/javascript">//<![CDATA[
var switch_mode = document.getElementById('switch_mode');
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "op_mode")%>', null, function(x, status) {
if ( x && x.status == 200 ) {
if ( status.op_mode == "redir-host" ) {
switch_mode.innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch page to Fake-IP mode%>" onclick="return switch_modes(this)"/>';
}
else {
switch_mode.innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch page to Redir-Host mode%>" onclick="return switch_modes(this)"/>';
}
}
});
function switch_modes(btn)
{
btn.disabled = true;
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "switch_mode")%>', null, function(x, status) {
if ( x && x.status == 200 ) {
if ( status.switch_mode == "redir-host" ) {
alert('<%:Page has been switched to Fake-IP mode!%>')
window.location.href='<%="settings"%>';
}
else {
alert('<%:Page has been switched to Redir-Host mode!%>')
window.location.href='<%="settings"%>';
}
}
});
btn.disabled = false;
return false;
}
//]]></script>