/** * Copyright 2016 Ludovic Pouzenc * * CHD OpenWRT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * CHD OpenWRT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with CHD OpenWRT. If not, see . **/ /* document.onreadystatechange = function () { console.log("document.onreadystatechange"); }; document.onunload = function () { console.log("document.onunload"); for(var i=0; i<1000000000; i++) {} };*/ document.addEventListener("DOMContentLoaded", function() { console.log("DOMContentLoaded"); // HTML5 form validation var supports_input_validity = function() { var i = document.createElement("input"); return "setCustomValidity" in i; } if(supports_input_validity()) { var pwd1Input = document.getElementById("field_pwd1"); var pwd2Input = document.getElementById("field_pwd2"); var key1Input = document.getElementById("field_key1"); var key2Input = document.getElementById("field_key2"); pwd2Input.addEventListener("keyup", function() { this.setCustomValidity( (this.value!=pwd1Input.value)?pwd2Input.title:"" )}, false); key2Input.addEventListener("keyup", function() { this.setCustomValidity( (this.value!=key1Input.value)?key2Input.title:"" )}, false); } /* Range slider value update var txpower = document.getElementById("field_txpower"); var txpowerText = document.getElementById("field_txpower_text"); txpower.addEventListener("change", function(e) { txpowerText.value=txpower.value + " dB"; }, true); */ var btn_gen = document.getElementById("btn_gen"); btn_gen.value="Téléchager le fichier de mise à jour"; // Additionnal form validation (on submit) var checkForm = function(e) { if (this.pwd1.value != this.pwd2.value) { this.pwd1.focus(); e.preventDefault(); return; } if (this.key1.value != this.key2.value) { this.key1.focus(); e.preventDefault(); return; } // Safari needs this one too if (!e.target.checkValidity()) { e.preventDefault(); return; } // Form will pass, disable the form button to prevent multiple clicks var btn_gen = document.getElementById("btn_gen"); btn_gen.value="Patientez puis sauvez le fichier"; btn_gen.disabled=true; btn_gen.style.color="gray"; }; var form_main = document.getElementById("form_main"); form_main.addEventListener("submit", checkForm, true); // Guess of current LAN gateway var field_ip4lan = document.getElementById("field_ip4lan"); getIPs(function(ip){ console.log(ip); var res = ip.match(/^192\.168\.\d+/); if ( res ) { // Dumb guess of gateway IP field_ip4lan.value = res + ".1"; } }); }, false); window.addEventListener('unload', function(event) { console.log('unload'); // Revert submit button to inital state if history.go(-1) was used var btn_gen = document.getElementById("btn_gen"); btn_gen.value="Télécharger le fichier de mise à jour"; btn_gen.disabled=false; btn_gen.style.color="black"; }); // LAN IPs detection function getIPs(callback){ var ip_dups = {}; //compatibility for firefox and chrome var RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; var useWebKit = !!window.webkitRTCPeerConnection; if(!RTCPeerConnection){ return; // The following code pops JS errors on Safari } //bypass naive webrtc blocking using an iframe if(!RTCPeerConnection){ //NOTE: you need to have an iframe in the page right above the script tag // // //