Skip to content
This repository was archived by the owner on Apr 27, 2025. It is now read-only.

Commit 0c4d3bf

Browse files
authored
Merge pull request #15 from the13-HK/faeture/show-ipv4-and-ipv6
FEAT Show IPV4 and IPV6
2 parents a43cadb + c338dd1 commit 0c4d3bf

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

server.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function generateHomeViewData(lang, ip, info) {
7373
'title' : i18next.t('title'),
7474
'ip': ip,
7575
'ipinfo' : info,
76+
'ipinfo_domain' : ip.includes(':') ? 'ipinfo.io': 'v6.ipinfo.io',
7677
'home_description': i18next.t('home-description'),
7778
'html_lang': lang == 'en' ? 'en' : 'pt_BR',
7879
'your_current_ip': i18next.t('your-current-ip'),
@@ -134,7 +135,6 @@ app.get('/en', async (req, res) => {
134135
const ip = req.ip;
135136
getIPInfo((info) => {
136137
info = JSON.parse(info);
137-
138138
var viewdata = generateHomeViewData('pt', ip, info);
139139

140140
res.render('index', viewdata);

views/index.html

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ <h1>
4040

4141
<h2 class="second-title">{{ your_current_ip }}</h2>
4242
<div class="splash-head">
43-
<span>{{ ip }}</span>
43+
<p>{{ ip }}</p>
4444
</div>
4545
<br>
4646
<div class="pure-g ipinfo">
@@ -86,6 +86,24 @@ <h2 class="second-title">{{ your_current_ip }}</h2>
8686
});
8787
</script>
8888

89+
<script>
90+
const featchData = fetch("https://{{ ipinfo_domain }}?callback")
91+
.then(response => {
92+
if (response.status !== 200) {
93+
throw Error();
94+
}
95+
return response.json()})
96+
.then(data => {
97+
if (data.ip != "{{ ip }}" && data.ip != "") {
98+
const newSpan = document.createElement('p');
99+
newSpan.textContent = data.ip;
100+
document.querySelector('.splash-head').appendChild(newSpan);
101+
}
102+
}).catch(error => {
103+
console.log("Could not obtain second IP");
104+
});
105+
</script>
106+
89107
<!-- Place this tag in your head or just before your close body tag. -->
90108
<script async defer src="https://buttons.github.io/buttons.js"></script>
91109

0 commit comments

Comments
 (0)