巴哈姆特之顯示文章ip所在國籍

根據巴哈給的文章ip顯示對應的國旗

目前為 2022-02-26 提交的版本,檢視 最新版本

// ==UserScript==
// @name         巴哈姆特之顯示文章ip所在國籍
// @description  根據巴哈給的文章ip顯示對應的國旗
// @namespace    nathan60107
// @author       nathan60107(貝果)
// @version      1.5
// @license      MIT
// @homepage     https://home.gamer.com.tw/homeindex.php?owner=nathan60107
// @match        https://forum.gamer.com.tw/C*
// @icon         https://forum.gamer.com.tw/favicon.ico
// @grant        GM_xmlhttpRequest
// @connect      ip-api.com
// @run-at       document-end
// @noframes
// ==/UserScript==

(function() {
    let bahaip = "104.16.181.30"
    let rawips = jQuery(".edittime.tippy-post-info").map(function() {
        return this.dataset.hideip;
    }).toArray()
    let ips = rawips.map(item => {
        if(item.match(/\d+.\d+.\d+.xxx/)){
            return item.replace("xxx", "000")
        }else{
            return bahaip
        }
    })

    function setCountryFlag(rawdata){
        let data = JSON.parse(rawdata.response)
        let users = jQuery(".c-post__header__author")

        for(let i = 0; i < Math.min(data.length, users.length); i++){
            let img = (ips[i] === bahaip) ? `https://forum.gamer.com.tw/favicon.ico` : `https://flagicons.lipis.dev/flags/4x3/${data[i].countryCode.toLowerCase()}.svg`
            jQuery(users[i].children[0]).after(`<img src="${img}" title="${data[i].country}" style="vertical-align: middle; height: 26px; border-radius:4px;">`)
        }
    }

    GM_xmlhttpRequest ( {
        method:     "POST",
        url:        "http://ip-api.com/batch?fields=countryCode,country",
        data:       JSON.stringify(ips),
        headers:    {
            "Content-Type": "application/x-www-form-urlencoded"
        },
        onload:     setCountryFlag,
    } );
})();

QingJ © 2025

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