想要在隐私协议里面添加展示用户自己会被暴露的信息,研究了一个获取用户信息并展示的方法,利用了ipip.net来获取用户的ip和地理信息。

Demo

Demo

引入js

创建custom.js,并且引入到inject

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(async function() {
async function getIpInfo() {
var fetchUrl = "https://api.qjqq.cn/api/Local";
try {
var response = await fetch(fetchUrl);
var json = await response.json();

var ip = json.ip;
var country = json.data.country;
var prov = json.data.prov;
var city = json.data.city;
var isp = json.data.isp;

document.getElementById("userAgentIp").innerHTML = ip;
document.getElementById("userAgentCountry").innerHTML = country;
document.getElementById("userAgentProv").innerHTML = prov;
document.getElementById("userAgentCity").innerHTML = city;
document.getElementById("userAgentISP").innerHTML = isp;


var uaInfo = navigator.userAgent;

document.getElementById("userAgentDevice").innerHTML = uaInfo;
} catch (error) {
console.error("An error occurred while fetching IP info:", error);
}
}

await getIpInfo();
})();

页面引入MarkDown

1
2
3
4
5
6
7
8
| 类型<div style="width:100px">          | 信息                                  |
|-------------|-------------------------------------|
| IP地址 | <div id="userAgentIp"></div> |
| 国家 | <div id="userAgentCountry"></div> |
| 省份 | <div id="userAgentRegion"></div> |
| 城市 | <div id="userAgentCity"></div> |
| 运营商 | <div id="userAgentIsp"></div> |
| 设备 | <div id="userAgentDevice"></div> |