Skip to content

Commit

Permalink
امکان پشتیبانی از کانفیگ‌های ویمس
Browse files Browse the repository at this point in the history
  • Loading branch information
ircfspace committed Apr 22, 2023
1 parent 64ec410 commit 243397d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
37 changes: 33 additions & 4 deletions assets/js/script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const protocols = ["vless", "trojan"];
const protocols = ["vless", "trojan", "vmess"];
let pregIp = /(?:^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$)|(?:^(?:(?:[a-fA-F\d]{1,4}:){7}(?:[a-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|:[a-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,2}|:)|(?:[a-fA-F\d]{1,4}:){4}(?:(?::[a-fA-F\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,3}|:)|(?:[a-fA-F\d]{1,4}:){3}(?:(?::[a-fA-F\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,4}|:)|(?:[a-fA-F\d]{1,4}:){2}(?:(?::[a-fA-F\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,5}|:)|(?:[a-fA-F\d]{1,4}:){1}(?:(?::[a-fA-F\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,6}|:)|(?::(?:(?::[a-fA-F\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-fA-F\d]{1,4}){1,7}|:)))(?:%[0-9a-zA-Z]{1,})?$)/gm;

function isValidIp(ipaddress) {
Expand Down Expand Up @@ -50,10 +50,38 @@ function findDefIp(pastedConfig) {

function updateConfig(ip) {
let pastedConfig = $('#defConfig').val();
let findIp = findDefIp(pastedConfig);
pastedConfig = pastedConfig.replace(findIp, ip);
let provider = $('#provider').val();
return pastedConfig+(provider !== "" ? "_"+provider.toUpperCase() : "");
if ( getProtocol(pastedConfig) === 'vmess' ) {
let oldConf = base64Decode(pastedConfig);
oldConf.add = ip;
oldConf.ps = oldConf.ps+(provider !== "" ? "_"+provider.toUpperCase() : "");
let newConf = base64Encode(oldConf);
return 'vmess://'+newConf;
}
else {
let findIp = findDefIp(pastedConfig);
pastedConfig = pastedConfig.replace(findIp, ip);
return pastedConfig+(provider !== "" ? "_"+provider.toUpperCase() : "");
}
}

function base64Decode(config) {
try {
config = config.replace("vmess://", "");
return JSON.parse(atob(config));
}
catch {
return {};
}
}

function base64Encode(object) {
try {
return btoa(JSON.stringify(object));
}
catch {
return "";
}
}

$(document).on('keyup', '#defConfig', function(e) {
Expand All @@ -67,6 +95,7 @@ $(document).on('keyup', '#defConfig', function(e) {
}
$('#protocolAlert').addClass('none');
$('#pastedList').trigger('keyup');

});

$(document).on('change', '#provider', function(e) {
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h1>اینترنت برای همه؛ یا هیچ‌کس!</h1>
<div class="alert alert-warning none" id="protocolAlert">
<p>تنها پروتکل‌های VLESS و TROJAN پشتیبانی می‌شوند.</p>
</div>
<input class="form-control dirLeft" placeholder="Vless/Trojan config" id="defConfig" />
<input class="form-control dirLeft" placeholder="Vless, Vmess or Trojan" id="defConfig" />
<textarea class="form-control dirLeft" id="pastedList" placeholder="1.1.1.1"></textarea>
<div class="input-group fetchIps">
<select class="form-control" id="provider">
Expand Down Expand Up @@ -169,7 +169,7 @@ <h4 class="modal-title">دونیت</h4>
</div>
<script src="./assets/js/jquery.min.js"></script>
<script src="./assets/js/bootstrap.min.js"></script>
<script src="./assets/js/script.js?v1.0.2"></script>
<script src="./assets/js/script.js?v1.1"></script>
<script>
window.addEventListener('load', function() {
let yourConfig = localStorage.getItem("defConfig");
Expand Down

0 comments on commit 243397d

Please sign in to comment.