mirror of
https://github.com/techgarage-ir/MTWireGuard.git
synced 2025-08-31 15:19:28 +02:00
Use new front-end based on Dashmin template
This commit is contained in:
parent
c118242c5b
commit
dbd7fafb34
4391 changed files with 228401 additions and 73494 deletions
84
UI/wwwroot/js/helper.js
Normal file
84
UI/wwwroot/js/helper.js
Normal file
|
@ -0,0 +1,84 @@
|
|||
class toastMessage {
|
||||
constructor(title, message, time, background) {
|
||||
this.title = title;
|
||||
this.message = message;
|
||||
this.time = time;
|
||||
this.background = background;
|
||||
}
|
||||
|
||||
getElement() {
|
||||
return $(`<div id="liveToastClass" class="toast text-bg-${this.background}" role="alert" aria-live="assertive" aria-atomic="true" data-bs-autohide="false">` +
|
||||
` <div class="toast-header">` +
|
||||
` <i class="bi bi-info-lg"></i>` +
|
||||
` <strong class="me-auto">${this.title}</strong>` +
|
||||
` <small class="text-body-secondary">${this.time}</small>` +
|
||||
` <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>` +
|
||||
` </div>` +
|
||||
` <div class="toast-body">` +
|
||||
` ${this.message}` +
|
||||
` </div>` +
|
||||
`</div>`);
|
||||
}
|
||||
|
||||
getInstance() {
|
||||
return bootstrap.Toast.getOrCreateInstance(this.getElement());
|
||||
}
|
||||
}
|
||||
|
||||
function randomBgColor() {
|
||||
var index = Math.floor(Math.random() * 6);
|
||||
var colors = ['success', 'danger', 'warning', 'info', 'dark', 'primary', 'secondary'];
|
||||
return colors[index];
|
||||
}
|
||||
|
||||
function convertByteSize(value, decimalPlaces = 2) {
|
||||
if (decimalPlaces < 0) {
|
||||
throw new Error("decimalPlaces must be non-negative.");
|
||||
}
|
||||
if (value < 0) {
|
||||
return `-${convertByteSize(-value, decimalPlaces)}`;
|
||||
}
|
||||
if (value === 0) {
|
||||
return "0";
|
||||
}
|
||||
|
||||
const sizeSuffixes = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
||||
|
||||
const mag = Math.floor(Math.log(value) / Math.log(1024));
|
||||
|
||||
const adjustedSize = value / (1 << (mag * 10));
|
||||
|
||||
if (Math.round(adjustedSize, decimalPlaces) >= 1000) {
|
||||
mag++;
|
||||
adjustedSize /= 1024;
|
||||
}
|
||||
|
||||
return `${adjustedSize.toFixed(decimalPlaces)} ${sizeSuffixes[mag]}`;
|
||||
}
|
||||
|
||||
function getIPInfo(ipAddress) {
|
||||
const url = 'https://ipinfo.techgarage.ir/get_info';
|
||||
|
||||
const request = new XMLHttpRequest();
|
||||
request.open('POST', url, false);
|
||||
|
||||
let formData = new FormData();
|
||||
formData.append("ip", ipAddress);
|
||||
formData.append("ipv", "4");
|
||||
formData.append("source", "ipregistry");
|
||||
|
||||
request.send(formData);
|
||||
|
||||
if (request.status !== 200) {
|
||||
console.error('Failed to fetch data');
|
||||
return null;
|
||||
}
|
||||
|
||||
const data = JSON.parse(request.responseText).ipregistry;
|
||||
data.country = data.country ? formatCountryName(data.country) : "N/A";
|
||||
return data;
|
||||
}
|
||||
|
||||
function formatCountryName(country) {
|
||||
return country.length <= 4 ? country.toUpperCase() : country;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue