-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchito.user.js
55 lines (50 loc) · 1.55 KB
/
chito.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// ==UserScript==
// @name Chito 后台评论地理位置显示
// @namespace https://github.com/lilydjwg/userscripts
// @description 通过 JSONP 查询 IP 地址对应的地理位置并显示
// @include http://*.is-programmer.com/admin*
// @include http://blog.lilydjwg.me/admin*
// @include https://blog.lilydjwg.me/admin*
// @version 1.1
// @grant GM_xmlhttpRequest
// ==/UserScript==
const qurl = function(ips){
return 'http://localhost:4321/queryip?q=' + ips.join(',')
}
const letsJQuery = function(){
const ip_header = document.evaluate(
'//th[@class="helpHed" and text()="IP"]',
document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null
).snapshotItem(0)
const ip_cells = document.getElementsByClassName('comment_ip_col')
const ips = []
let i, len
for(let cell of ip_cells){
ips.push(cell.textContent)
}
GM_xmlhttpRequest({
method: 'GET',
url: qurl(ips),
headers: {
Accept: 'application/json',
},
onload: function(response) {
const ans = JSON.parse(response.responseText).ans
for(i=0, len=ip_cells.length; i<len; i++){
$(ip_cells[i]).after('<td class="comment_addr_col" style="min-width: 10em;">'+ans[i]+'</td>')
}
$(ip_header).after('<th class="helpHed">地址</th>')
},
})
}
function GM_wait(){
if(/\/(comments|messages|spams)\b/.test(location)){
if(typeof unsafeWindow.jQuery == 'undefined') {
setTimeout(GM_wait, 500)
}else{
$ = unsafeWindow.jQuery
letsJQuery()
}
}
}
GM_wait()