BYR BBS ip2location

使北邮人论坛用户发贴IP地址后附加物理地址信息

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           BYR BBS ip2location
// @namespace      http://bbs.byr.cn/
// @description	   使北邮人论坛用户发贴IP地址后附加物理地址信息
// @include        http://forum.byr.edu.cn/*
// @include        http://forum.byr.cn/*
// @include        http://bbs.byr.edu.cn/*
// @include        http://bbs6.byr.edu.cn/*
// @include        http://bbs.byr.cn/*
// @include        http://bbs6.byr.cn/*
// @include        http://www.newsmth.net/*
// @version        1.7
// @author         Binux
// @author         John Wong
// ==/UserScript==

function showLoading(ip, font){
	var span = document.createElement("span");
	span.innerHTML = " [ LOADING... ]";
	span.className = ip;
	font.appendChild(span);
}

function onLoad(event) {
	var fonts = document.getElementsByTagName("font");
	for ( var i = 0,font;font = fonts[i];i++ )
	{
		var result = font.innerHTML.match(/\[FROM:\D{0,5}([0-9a-fA-F\.:]+.)\]/);
		if(result && font.lastChild.nodeName != "SPAN")
		{
			var ip = result[1].replace("*","0");
			showLoading(ip, font);
			sendRequest(ip);
			return;
		}
	}
}

function sendRequest(ip){
    setTimeout(function() {GM_xmlhttpRequest({
    method: 'GET',
    url: 'https://pytool.sinaapp.com/geo?type=json&pos=1&ip='+ip,
    onload: function(responseDetails) {
        var response = responseDetails.responseText;
        var ret = eval('(' + response + ')')['geo']
		var ip = ret['ip']
        var loc = ret['loc']
        showAddress({'ip': ip,'loc': loc});
        }
    })}, 0);
}

function showAddress(response){
	var spans = document.getElementsByClassName(response.ip);
	for(var i=0,span;span = spans[i];i++){
		span.innerHTML = " [" + response.loc + "] ";
	}
}

onLoad();
window.addEventListener("load", onLoad, false);
window.addEventListener("AutoPagerAfterInsert", onLoad, false);
document.addEventListener("DOMNodeInserted", onLoad, false);