-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.js
43 lines (36 loc) · 927 Bytes
/
main.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
const axios = require('axios')
const fs = require('fs')
async function main () {
const path = await getPath()
console.log('Config路径:' + path)
if (path === '') return
getClashConfig(path)
}
async function getPath () {
// 地址已失效
const url = "http://feeds.feedburner.com/mattkaydiary/pZjG"
let response = await axios.get(url)
const html = response.data || ""
let pathArr = html.match(/(?<=clash\(请开启代理后再拉取\):)(.*?)(?=<\/div>)/g) || []
console.log('pathArr:' + pathArr)
let path = ""
if (pathArr.length > 0) {
path = pathArr[0].replace(/amp;/g, '')
}
return path
}
function getClashConfig (path) {
axios.get(path).then(response => {
let data = response.data || ''
if (data !== '') writeFile(data)
})
}
function writeFile (data) {
fs.writeFile('./Clash.yaml', data, err => {
if (err)
console.log('error')
else
console.log('success')
})
}
main()