Skip to content

Commit

Permalink
Create script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
opiran-club authored Aug 17, 2024
1 parent ca1b8f5 commit 12640f3
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
functionconvertToURL() {
const config = document.getElementById('configInput').value;
const lines = config.split('\n');
let privateKey = '', publicKey = '', address = '', mtu = '', endpoint = '', port = '';

lines.forEach(line => {
if (line.includes('Secret Key')) {
privateKey = line.split(' ').pop();
}
if (line.includes('Public Key')) {
publicKey = line.split(' ').pop();
}
if (line.includes('Address')) {
address = line.split(' ').pop();
}
if (line.includes('MTU')) {
mtu = line.split(' ').pop();
}
if (line.includes('Endpoint')) {
const endpointParts = line.split(' ').pop().split(':');
endpoint = endpointParts[0];
port = endpointParts[1];
}
});

const url = `wireguard://${encodeURIComponent(privateKey)}@${endpoint}:${port}/?publickey=${encodeURIComponent(publicKey)}&address=${encodeURIComponent(address)}&mtu=${encodeURIComponent(mtu)}#test`;

document.getElementById('output').innerText = url;
}

0 comments on commit 12640f3

Please sign in to comment.