Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show qrcode at result page #221

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 40 additions & 19 deletions src/worker-vless.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,32 @@ export default {
case '/':
return new Response(JSON.stringify(request.cf), { status: 200 });
case `/${userID}`: {
const vlessConfig = getVLESSConfig(userID, request.headers.get('Host'));
return new Response(`${vlessConfig}`, {
const [vlessMain, vlessConfig] = getVLESSConfig(userID, request.headers.get('Host'));
const html = `<!DOCTYPE html>
<body>
<title>connect info</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>

<h1>scan qrcode to connect.</h1>

<div id="qrcode"></div>

<br/>

<script type="text/javascript">
new QRCode(document.getElementById("qrcode"), "${vlessMain}");
</script>

<br/>

<pre>${vlessConfig}</pre>

</body>`;
return new Response(`${html}`, {
status: 200,
headers: {
"Content-Type": "text/plain;charset=utf-8",
"content-type": "text/html;charset=UTF-8",
}
});
}
Expand Down Expand Up @@ -600,8 +621,8 @@ async function handleUDPOutBound(webSocket, vlessResponseHeader, log) {
* @returns {string}
*/
function getVLESSConfig(userID, hostName) {
const vlessMain = `vless://${userID}@${hostName}:443?encryption=none&security=tls&sni=${hostName}&fp=randomized&type=ws&host=${hostName}&path=%2F%3Fed%3D2048#${hostName}`
return `
const vlessMain = `vless://${userID}@${hostName}:443?encryption=none&security=tls&sni=${hostName}&fp=randomized&type=ws&host=${hostName}&path=%2F%3Fed%3D2048#${hostName}`;
const result = `
################################################################
v2ray
---------------------------------------------------------------
Expand All @@ -611,21 +632,21 @@ ${vlessMain}
clash-meta
---------------------------------------------------------------
- type: vless
name: ${hostName}
server: ${hostName}
port: 443
uuid: ${userID}
network: ws
tls: true
udp: false
sni: ${hostName}
client-fingerprint: chrome
ws-opts:
path: "/?ed=2048"
headers:
host: ${hostName}
name: ${hostName}
server: ${hostName}
port: 443
uuid: ${userID}
network: ws
tls: true
udp: false
sni: ${hostName}
client-fingerprint: chrome
ws-opts:
path: "/?ed=2048"
headers:
host: ${hostName}
---------------------------------------------------------------
################################################################
`;
return [vlessMain, result];
}