显示网站ip

在所有网站右下角显示ip

当前为 2025-01-10 提交的版本,查看 最新版本

// ==UserScript==
// @name         显示网站ip
// @namespace    http://tampermonkey.net/
// @version      2025-01-10
// @description  在所有网站右下角显示ip
// @author       Rakiwine
// @match        *://*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=chatgpt.com
// @grant        GM_getResourceText
// @grant        GM_addStyle
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    function extractIPs(text) {
        const regex = /\b(?:\d{1,3}\.){3}\d{1,3}\b/g;
        const matches = text.match(regex);
        return matches || [];
    }

    async function getIP(domain) {
        const response = await fetch(`https://dns.google/resolve?name=${domain}`);
        const data = await response.json();
        const ips = data.Comment ? extractIPs(data.Comment) : null;
        return ips;
    }

    getIP(location.origin).then(ips => {
        const buttonId = 'G7z_$nK4Hq2r_X1P';

        // 检查按钮是否已经存在
        if (!document.getElementById(buttonId)) {
            // 创建按钮元素
            const button = document.createElement('button');
            button.id = buttonId; // 设置按钮的 ID 为唯一标识符
            button.textContent = ips;

            // 添加样式
            button.style.backgroundColor = 'rgba(0, 0, 0, 0.5)'; // 黑色半透明
            button.style.color = 'white'; // 文字颜色
            button.style.border = 'none'; // 去掉边框
            button.style.borderRadius = '16px'; // 圆角
            button.style.height = '50px'; // 高度
            button.style.padding = '0px 20px'; // 左右内边距
            button.style.fontSize = '30px'; // 字体大小
            button.style.cursor = 'pointer'; // 鼠标悬停时显示手型光标
            button.style.outline = 'none'; // 去掉焦点时的轮廓
            button.style.position = 'fixed'; // 固定定位
            button.style.bottom = '10px'; // 距离顶部 10px
            button.style.right = '10px'; // 距离右边 10px
            button.style.zIndex = '1000'; // 确保按钮在最上层
            button.style.pointerEvents = 'none'; // 点击穿透

            // 将按钮添加到 body 中
            document.body.appendChild(button);


        }
    }).catch(data => data);

    // fetch('https://api.ipify.org?format=json').then(results => results.json()).then(data => data.ip);

    // Your code here...
})();