知乎显示IP属地

在知乎回答中显示作者IP属地

目前為 2025-01-07 提交的版本,檢視 最新版本

// ==UserScript==
// @name         知乎显示IP属地
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  在知乎回答中显示作者IP属地
// @author       You
// @match        https://www.zhihu.com/*
// @grant        GM_xmlhttpRequest
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 添加CSS样式
    const style = document.createElement('style');
    style.textContent = `
        .ip-location {
            font-size: 12px;
            color: #8590a6;
            margin-top: 4px;
        }
    `;
    document.head.appendChild(style);

    // 获取作者主页链接并添加IP属地信息
    function addIPLocation() {
        const authorLinks = document.querySelectorAll('.UserLink-link');
        
        authorLinks.forEach(link => {
            if(link.dataset.processed) return; // 避免重复处理
            link.dataset.processed = true;
            
            const authorUrl = link.href;
            const authorInfoDiv = link.closest('.AuthorInfo-content');
            
            if(!authorInfoDiv) return;

            // 创建IP属地显示元素
            const ipDiv = document.createElement('div');
            ipDiv.className = 'ip-location';
            authorInfoDiv.appendChild(ipDiv);

            // 获取作者主页HTML
            GM_xmlhttpRequest({
                method: 'GET',
                url: authorUrl,
                onload: function(response) {
                    const parser = new DOMParser();
                    const doc = parser.parseFromString(response.responseText, 'text/html');
                    
                    // 查找IP属地信息
                    const ipElement = doc.querySelector('.css-1xfvezd');
                    if(ipElement) {
                        const ipText = ipElement.textContent;
                        ipDiv.textContent = ipText;
                    }
                }
            });
        });
    }

    // 监听页面变化
    const observer = new MutationObserver(addIPLocation);
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    // 初始执行
    addIPLocation();
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址