Skip to content

Instantly share code, notes, and snippets.

@xymopen
Last active August 29, 2015 14:20
Show Gist options
  • Save xymopen/972809b8dbfef7a4102b to your computer and use it in GitHub Desktop.
Save xymopen/972809b8dbfef7a4102b to your computer and use it in GitHub Desktop.
ShadowX Profile
// ==UserScript==
// @name ShadowX Profile
// @namespace com.gmail.open.xuyiming
// @version 0.2
// @description 在 ShadowX 的节点页面显示 JSON 格式的配置信息
// @author +依然独特
// @match *://shadowx.work/user/node/*
// @match *://shadowx.co/user/node/*
// @include *://shadowx.work/user/node/*
// @include *://shadowx.co/user/node/*
// @grant none
// ==/UserScript==
( function() {
"use strict";
function decodeSSProtocol( ss ) {
"use strict";
// ss:\\{ Base32_encode( method:password@server:server_port ) }
var config = atob( ss.replace( /^ss:\/\//, "" ) )
.split( "@" )
.map( function( part ) {
return part.split( ":" );
} );
return {
"server": config[ 1 ][ 0 ],
"server_port": parseInt( config[ 1 ][ 1 ], 10 ),
"password": config[ 0 ][ 1 ],
"method": config[ 0 ][ 0 ]
};
};
document.addEventListener( "DOMContentLoaded", function() {
var info_box, link_p, profile, pre,
qrcode = document.getElementById( "qrcode" );
if ( qrcode ) {
info_box = qrcode.parentElement.parentElement;
link_p = info_box.getElementsByTagName( "p" )[0];
profile = decodeSSProtocol( link_p.textContent.trim() );
pre = document.createElement( "pre" );
pre.textContent = "{" + "\n" +
"\t" + "\"server\": " + "\"" + profile.server + "\"" + ",\n" +
"\t" + "\"server_port\": " + profile.server_port + ",\n" +
"\t" + "\"password\": " + "\"" + profile.password + "\"" + ",\n" +
"\t" + "\"method\": " + "\"" + profile.method + "\"" + "\n" +
"}";
info_box.insertBefore( pre, link_p );
}
}, false );
} )();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment