Created
January 29, 2019 09:45
-
-
Save Hawksbillcat/deb3a6b364be0fb9aa0e2b7eed57d3a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.ReadWeb_promise = function (url) {//這裡是讀取網頁資料的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) {//抓資料 | |
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 () {//先爬IP的promise | |
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(){//第一個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(){//第二個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都是undefined 但是網頁要出來的資料有抓到? | |
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