kde-widget/com.umorist47.meowrelaygui/contents/ui/.unused.qml
2026-02-23 05:28:35 +03:00

163 lines
5.2 KiB
QML

// functions from main.qml --> reworked
// GET routes
function fetchRoutes() {
isLoading = true;
routeModel.clear();
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://10.7.0.1:7777/routes");
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
isLoading = false;
if (xhr.status === 200) {
var response = JSON.parse(xhr.responseText);
for (var i = 0; i < response.length; i++) {
routeModel.append(response[i]);
}
} else {
console.error("Failed to fetch routes:", xhr.status);
}
}
}
xhr.send();
}
// GET profile
function fetchProfile() {
//isLoading = true;
profileModel.clear();
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://10.7.0.1:7777/me/profile");
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
//isLoading = false;
if (xhr.status === 200) {
profileData = JSON.parse(xhr.responseText);
//for (var i = 0; i < response.length; i++) {
// profileModel.append(response[i]);
//}
} else {
console.error("Failed to fetch profile:", xhr.status);
}
}
}
xhr.send();
}
// GET stats
function fetchStats() {
//isLoading = true;
statsModel.clear();
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://10.7.0.1:7777/stats");
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
//isLoading = false;
if (xhr.status === 200) {
statsData = JSON.parse(xhr.responseText);
//for (var i = 0; i < response.length; i++) {
// profileModel.append(response[i]);
//}
} else {
console.error("Failed to fetch profile:", xhr.status);
}
}
}
xhr.send();
}
// POST select country
function selectCountry(code, provider) {
isLoading = true;
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://10.7.0.1:7777/me/country");
xhr.setRequestHeader("Content-Type", "application/json");
var data = JSON.stringify({
"countryCode": code,
"provider": provider
});
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
isLoading = false;
if (xhr.status === 200) {
console.log("Success: Changed to " + code);
} else {
console.error("POST failed:", xhr.status);
}
}
}
xhr.send(data);
}
// POST switch share
function switchShare(bool) {
//isLoading = true;
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://10.7.0.1:7777/me/profile");
xhr.setRequestHeader("Content-Type", "application/json");
var data = JSON.stringify({
"shareTraffic": bool
});
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
//isLoading = false;
if (xhr.status === 200) {
console.log("Success: Share changed to " + bool);
} else {
console.error("POST failed:", xhr.status);
}
}
}
xhr.send(data);
}
// POST switch ebalka
function switchEbalka(bool, ip) {
//isLoading = true;
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://10.7.0.1:7777/me/ebalka");
xhr.setRequestHeader("Content-Type", "application/json");
var data = JSON.stringify({
"ebalka": bool,
"ip": ip
});
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
//isLoading = false;
if (xhr.status === 200) {
console.log("Success: Ebalka for " + ip + " changed to " + bool);
} else {
console.error("POST failed:", xhr.status);
}
}
}
xhr.send(data);
}
// не смотрите сюда
function getFlag($code) {
if ($code == 'US') return '🇺🇸';
if ($code == 'FI') return '🇫🇮';
if ($code == 'EE') return '🇪🇪';
if ($code == 'DE') return '🇩🇪';
if ($code == 'AM') return '🇦🇲';
if ($code == 'AD') return '🇦🇩';
if ($code == 'GB') return '🇬🇧';
if ($code == 'MC') return '🇲🇨';
if ($code == 'HK') return '🇭🇰';
if ($code == 'ES') return '🇪🇸';
if ($code == 'RU') return '🇷🇺';
if ($code == 'CH') return '🇨🇭';
return '❔';
}