Skip to content

Instantly share code, notes, and snippets.

@Hawksbillcat
Created January 29, 2019 14:21
Show Gist options
  • Save Hawksbillcat/e169a273c3c1db286e39faf6aa0040a4 to your computer and use it in GitHub Desktop.
Save Hawksbillcat/e169a273c3c1db286e39faf6aa0040a4 to your computer and use it in GitHub Desktop.
$scope.ReadWeb_promise = function (url) {//parse web site for promise
return new Promise(function(resolve,reject){
var Login = $scope.mobileStore("Login", "", "GET");
var Pwd = $scope.mobileStore("Pwd", "", "GET");
var request = new XMLHttpRequest();
request.open("GET", url, false,Login,Pwd);
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200){
resolve(request.responseText)
}else{
reject("no")
}
}
}
request.send();
})
}
$scope.GetTokenFromText = function (text, start, finish) {//fetch data
var iStart, iFinish;
iStart = text.indexOf(start) + start.length;
iFinish = text.indexOf(finish, iStart);
if (iFinish == -1) iFinish = text.length;
if ((iStart) == iFinish) {
return "";
} else {
return text.substring(iStart, iFinish);
}
};
$scope.handle = function () {//get promise of IP
return new Promise(function(resolve,reject){
var successCallback = function(data) {
//$scope.ip[0] = data;
resolve(data)
}
var errorCallback = function(errMsg) {
reject(errMsg)
}
window.IpAddress.get( successCallback, errorCallback);
})
}
$scope.get_romig_5g=function(){//first promise
$scope.handle().then(function(res){
console.log("res "+res)
let url= "http://"+res+"/boafrm/formWlanRedirect?redirect-url=/wladvanced.htm&wlan_id=0";
return url
},function(err){
console.log(err)
err=err+"no ip"
return err
}).then(function(url){
console.log("url "+url)
$scope.ReadWeb_promise(url).then(function(text){
console.log(text)
var G5_r1 = $scope.GetTokenFromText(text,"var dot11k_enable = ",";");
var G5_r2 = $scope.GetTokenFromText(text,"var IEEE80211r_enable = ",";");
var G5_r3 = $scope.GetTokenFromText(text,"var IEEE80211v_enable = ",";");
if ( G5_r1 == 1 && G5_r2 == 1 && G5_r3 == 1){
$scope.Status["G5_r1"]=1;
$scope.Status["G5_roming_enable"]=true;
console.log($scope.Status["G5_roming_enable"]+" g5 roming promise")
}else{
$scope.Status["G5_r1"]=0;
$scope.Status["G5_roming_enable"]=false;
console.log($scope.Status["G5_roming_enable"]+" g5 roming promise")
}
})
})
}
$scope.get_romig_24g=function(){//second promise
$scope.handle().then(function(res){
console.log("res "+res)
let url= "http://"+res+"/boafrm/formWlanRedirect?redirect-url=/wladvanced.htm&wlan_id=1"
return url
},function(err){
console.log(err)
err=err+"no ip"
return err
}).then(function(url){
console.log("url "+url)
$scope.ReadWeb_promise(url).then(function(text){
console.log(text)
var G24_r1 = $scope.GetTokenFromText(text,"var dot11k_enable = ",";");
var G24_r2 = $scope.GetTokenFromText(text,"var IEEE80211r_enable = ",";");
var G24_r3 = $scope.GetTokenFromText(text,"var IEEE80211v_enable = ",";");
//alert("G24_r1 G24_r2 G24_r3 "+G24_r1 +G24_r2 +G24_r3 )
if ( G24_r1 == 1 && G24_r2 == 1 && G24_r3 == 1){
$scope.Status["G24_r1"]=1;
$scope.Status["G24_roming_enable"]=true;
console.log($scope.Status["G24_roming_enable"]+" g24 roming promise")
}else{
$scope.Status["G24_r1"]=0;
$scope.Status["G24_roming_enable"]=false;
console.log($scope.Status["G24_roming_enable"]+" g24 roming promise")
}
})
})
$scope.promiseArray=function(){//
let pro1=Promise.resolve($scope.get_romig_5g())
let pro2=Promise.resolve($scope.get_romig_24g())
const pro=[pro1,pro2]
Promise.all(pro).then(function(va){//va is undefined ,but i can get the data text from website
console.log(va)
}).catch(function(err){
console.log(err)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment