-
Notifications
You must be signed in to change notification settings - Fork 24
/
index.js
57 lines (51 loc) · 1.28 KB
/
index.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
56
57
const superagent = require('superagent')
const cherrio = require('cheerio')
const url = 'http://ss.ishadowx.com/'
const select = '.portfolio-items .portfolio-item'
// const select = '#free .container .row:nth-child(2) > .col-sm-4'
const translator = {
'IP Address': 'address',
'Port': 'port',
'Password': 'password',
'Method': 'method'
}
function parseServer (serverStr) {
let server = {}
serverStr.split('\n').forEach(function (line) {
let kv = line.split(':')
if (kv.length === 1) {
kv = line.split(':')
}
if (kv.length > 1) {
let key = kv[0].trim()
let val = kv[1].trim()
let trueKey = translator[key]
if (trueKey) {
server[trueKey] = val
}
}
})
return server
}
function loadFreeShadowsocks () {
let freeShadowsocks = []
return superagent.get(url).then(function (res) {
let $ = cherrio.load(res.text)
$(select).each(function (i, elem) {
freeShadowsocks.push(
parseServer(
$(this).text().trim()
)
)
})
return Promise.resolve(freeShadowsocks)
})
}
module.exports = loadFreeShadowsocks
if (require.main === module) {
loadFreeShadowsocks().then(function (freeShadowsocks) {
console.log(freeShadowsocks)
}, function (err) {
console.error(err)
})
}