Skip to content

Commit

Permalink
Merge pull request #130 from jason5ng32/dev
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
jason5ng32 authored Feb 27, 2024
2 parents 67b0b08 + bc368bf commit 33cb2b1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default {
// 加载完成后隐藏 loading
hideLoading() {
var loadingElement = document.getElementById("jn-loading");
let loadingElement = document.getElementById("jn-loading");
if (loadingElement) {
loadingElement.style.display = "none";
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/connectivity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ export default {
checkConnectivityHandler(test, isAlertToShow, onTestComplete) {
const beginTime = +new Date();
var img = new Image();
var timeout = setTimeout(() => {
let img = new Image();
let timeout = setTimeout(() => {
test.status = this.$t('connectivity.StatusUnavailable');
onTestComplete(false);
}, 3 * 1200);
Expand Down
38 changes: 32 additions & 6 deletions src/components/ipcheck.vue
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export default {
],
ipDataCards: [
{
id: "taobao",
id: "cnsource",
ip: "",
country_name: "",
region: "",
Expand All @@ -314,7 +314,7 @@ export default {
mapUrl: '/defaultMap.jpg',
mapUrl_dark: '/defaultMap_dark.jpg',
showMap: false,
source: "TaoBao",
source: "CN Source",
showASNInfo: false,
},
{
Expand Down Expand Up @@ -454,18 +454,40 @@ export default {
});
},
// 从中国来源获取 IP 地址
getIPfromCNSource() {
this.getIPFromIPIP().catch(() => {
this.getIPFromTaobao();
});
},
// 从淘宝获取 IP 地址
getIPFromTaobao() {
window.ipCallback = (data) => {
var ip = data.ip;
let ip = data.ip;
this.ipDataCards[0].source = "TaoBao";
this.fetchIPDetails(0, ip);
document.head.removeChild(script);
delete window.ipCallback;
};
var script = document.createElement("script");
let script = document.createElement("script");
script.src = "https://www.taobao.com/help/getip.php?callback=ipCallback";
document.head.appendChild(script);
document.head.removeChild(script);
},
// 从 IPIP.net 获取 IP 地址
async getIPFromIPIP() {
try {
const response = await fetch("https://myip.ipip.net/json");
const data = await response.json();
const ip = data.data.ip;
this.ipDataCards[0].source = "IPIP.net";
this.fetchIPDetails(0, ip);
} catch (error) {
console.error("Error fetching IP from IPIP.net:", error);
throw new Error("Failed to fetch IP from IPIP.net");
}
},
// 从特殊源获取 IP 地址
Expand Down Expand Up @@ -756,8 +778,8 @@ export default {
// 检查所有 IP 地址
async checkAllIPs() {
const ipFunctions = [
this.getIPfromCNSource,
this.getIPFromSpecial,
this.getIPFromTaobao,
this.getIPFromCloudflare_V4,
this.getIPFromCloudflare_V6,
this.getIPFromIpify_V4,
Expand Down Expand Up @@ -807,6 +829,10 @@ export default {
this.getIPFromTaobao(card);
this.$trackEvent('IPCheck', 'RefreshClick', 'TaoBao');
break;
case "IPIP.net":
this.getIPFromIPIP(card);
this.$trackEvent('IPCheck', 'RefreshClick', 'IPIP.net');
break;
default:
console.error("Undefind Source:", card.source);
}
Expand Down

0 comments on commit 33cb2b1

Please sign in to comment.