Created
April 23, 2011 02:24
-
-
Save binux/938181 to your computer and use it in GitHub Desktop.
ip2loc for byr forum (http://bbs.byr.cn) chrome extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
</head> | |
<body> | |
<script> | |
function fetchLocation(callback,ip) { | |
var req = new XMLHttpRequest(); | |
req.open("GET","http://www.youdao.com/smartresult-xml/search.s?type=ip&q="+ip,true); | |
req.onload = function() { | |
var response = req.responseText; | |
var ip = response.match(/<ip>(.*)<\/ip>/)[1]; | |
var loc = response.match(/<location>(.*)<\/location>/)[1]; | |
callback({'ip': ip,'loc': loc}); | |
} | |
req.send(null); | |
} | |
function onRequest(request, sender, callback) { | |
if(request.action == 'fetchLocation') { | |
fetchLocation(callback, request.ip); | |
} | |
} | |
chrome.extension.onRequest.addListener(onRequest); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onLoad() { | |
var fonts = document.getElementsByTagName("font"); | |
for ( var i = 0,font;font = fonts[i];i++ ) | |
{ | |
var result = font.innerText.match(/\[FROM:\D{0,5}(\d+\.\d+\.\d+\.[0-9*]+)\]/); | |
if(result && font.lastChild.nodeName != "SPAN") | |
{ | |
var ip = result[1].replace("*","0"); | |
var span = document.createElement("span"); | |
span.innerHTML = " [ LOADING... ]"; | |
span.className = ip; | |
font.appendChild(span); | |
sendRequest(ip) | |
} | |
} | |
} | |
function sendRequest(ip){ | |
chrome.extension.sendRequest({'action': 'fetchLocation','ip': ip},showAddress); | |
} | |
function showAddress(response){ | |
var spans = document.getElementsByClassName(response.ip); | |
for(var i=0,span;span = spans[i];i++){ | |
span.innerText = " [" + response.loc + "] "; | |
} | |
} | |
var IP2LOC_DOCUMENT_HIGHT = 0; | |
function checkDom() { | |
if (IP2LOC_DOCUMENT_HIGHT != document.height ) { | |
IP2LOC_DOCUMENT_HIGHT = document.height; | |
onLoad(); | |
} | |
setTimeout("checkDom()", 500); | |
} | |
checkDom(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "BYR-BBS-IP2LOCATION", | |
"version": "1.3", | |
"description": "The first extension that I made. By Binux[瓒冲厗鍙夎櫕]", | |
"background_page": "background.html", | |
"content_scripts": [ | |
{ | |
"matches": [ | |
"http://forum.byr.edu.cn/*", | |
"http://forum.byr.cn/*", | |
"http://bbs.byr.edu.cn/*", | |
"http://bbs6.byr.edu.cn/*", | |
"http://bbs.byr.cn/*", | |
"http://bbs6.byr.cn/*" | |
], | |
"js": ["ip2loc.js"], | |
"all_frames": true | |
} | |
], | |
"permissions": [ | |
"http://www.youdao.com/" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment