Created
October 11, 2018 06:02
-
-
Save BirkhoffLee/cba0f8a3cfe5daa452f77383d92e26bd to your computer and use it in GitHub Desktop.
This node script converts a base64-encoded ShadowSocks subscription string to a Surge proxies configuration.
This file contains 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
const querystring = require('querystring') | |
let args = process.argv.slice(2) | |
if (!args[0]) { | |
console.error("Usage: node index.js [subscribe_list_base64_encoded]") | |
process.exit(1) | |
} | |
const base64Decode = (encoded) => { | |
return Buffer.from(encoded, 'base64').toString() | |
} | |
let ssrLinks = base64Decode(args[0]).trim().split("\n") | |
let hosts = [] | |
ssrLinks.forEach(link => { | |
let serverInfo = base64Decode(link.slice(6)).split(":") | |
let host = serverInfo[0] | |
let port = serverInfo[1] | |
let protocol = serverInfo[2] | |
let encoding = serverInfo[3] | |
let obfs = serverInfo[4] | |
let temp = serverInfo[5].split("/") | |
let password = base64Decode(temp[0]) | |
let params = temp[1] | |
if (params.slice(0, 1) === "?") | |
params = params.slice(1) | |
if (parseInt(port) == 0) return | |
params = querystring.parse(params) | |
Object.keys(params).forEach(property => { | |
params[property] = base64Decode(params[property]).trim() | |
}) | |
hosts.push({ | |
host: host.trim(), | |
port: port.trim(), | |
protocol: protocol.trim(), | |
encoding: encoding.trim(), | |
obfs: obfs.trim(), | |
password: password.trim(), | |
params: params | |
}) | |
}, this) | |
surgeList = hosts.map((el, idx) => { | |
return `${el.params.remarks} = ss, ${el.host}, ${el.port}, encrypt-method=${el.encoding}, password=${el.password}` | |
}) | |
surgeList.unshift("[Proxy]") | |
surgeList.push("") | |
surgeList.push("[Proxy Group]") | |
surgeList.push("PROXY = select, " + hosts.map(el => el.params.remarks).join(", ")) | |
console.log(surgeList.join("\n")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment