Jelajahi Sumber

fix: https use php file

Hugh Harlequin 1 tahun lalu
induk
melakukan
96110cab6b
1 mengubah file dengan 3 tambahan dan 1 penghapusan
  1. 3 1
      index.js

+ 3 - 1
index.js

@@ -9,13 +9,15 @@ xhr.addEventListener("loadend", async function (e){
     let responseObj = JSON.parse(this.response);
     let ip = responseObj.ip;
     let regionData = await ipToRegion(ip);
+    let country = window.location.protocol === 'https:' ? regionData.country_name : regionData.geoplugin_countryName
     if (window.regionMap[regionData.geoplugin_countryName]) {
         window.location.href = window.regionMap[regionData.geoplugin_countryName]
     }
 });
 xhr.send();
 async function ipToRegion(ip) {
-    const response = await fetch(`http://www.geoplugin.net/json.gp?ip=${ip}`);
+    let url = window.location.protocol === 'https:' ? `/ipdata.php?ip=${ip}` : `http://www.geoplugin.net/json.gp?ip=${ip}`
+    const response = await fetch(url);
     const data = await response.json();
     return data;
 }