function addCommaForGrands(num) {
let str = num.toString();
let result = '';
while (str.length > 3) {
result = ',' + str.slice(-3) + result;
str = str.slice(0, -3);
}
if (str.length) result = str + result;
return result;
}
function getChannelDataFromString(s) {
if (s.length < 3) return null;
var split = s.split(";&;");
if (split.length < 5) return null;
var status_id = parseInt(split[0].trim());
var status_changed_at = new Date(split[1].trim());
var name = split[2].trim();
var tg_link = split[3].trim();
var users_cnt = parseInt(split[4].trim()) - 1;
var latitude = NaN;
var longitude = NaN;
if (split.length == 7) {
var latitude = parseFloat(split[5].trim());
var longitude = parseFloat(split[6].trim());
}
if (isNaN(status_id)) status_id = 0;
return {
status_id: status_id,
status_changed_at: status_changed_at,
link: tg_link,
title: name,
users: users_cnt,
latitude: latitude,
longitude: longitude,
}
}
function fillTGChannels(arr, addButtonLoadMore)
{
arr.sort((a, b) => (a.users < b.users) ? 1 : -1)
var container = document.getElementById('my_channels_container');
if (addButtonLoadMore) container.innerHTML = "";
// Loop through the array
for (var i = 0; i < arr.length; i++) {
// Get the current channel
var channel = arr[i];
// Create the HTML block
var html = '
';
// Append the HTML block to the container
container.innerHTML += html;
}
//load more
if (addButtonLoadMore == true) {
let buttonLoadMore = '';
container.innerHTML += buttonLoadMore;
}
updateLangWebsiteContents();
document.body.style.cursor = 'default';
}
var loadMoreChannels_array = [];
function loadMoreChannels(button) {
$(button).remove();
document.body.style.cursor = 'wait';
setTimeout(fillTGChannels, 0, loadMoreChannels_array, false);
}
function indexFillStats() {
var api = PYTHON_API_URL + "website";
$.get(api + "/getChannelsAndPingsCount").done(function(data){
var channels_cnt = parseInt(data.split(";")[0]);
$("#myslider_channels_cnt div").attr("data-kt-countup-value", channels_cnt).attr("data-kt-countup", true).text(addCommaForGrands(channels_cnt));
var pings_cnt = parseInt(data.split(";")[1]);
$("#myslider_queries_cnt #mycounter").attr("data-kt-countup-value", pings_cnt).attr("data-kt-countup", true).text(addCommaForGrands(pings_cnt));
});
$.get(api + "/getChannels").done(function(data){
var total_users_cnt = 0;
// Set the array of parameters
var tg_channels_arr = [];
var split = data.split("\n");
for (var i = 0; i < split.length; i++) {
var line = split[i];
el = getChannelDataFromString(line);
if (el == null) continue;
if (el.users <= 0) continue;
tg_channels_arr.push(el);
total_users_cnt += el.users;
}
//SLIDER USERS
$("#myslider_users_cnt div").attr("data-kt-countup-value", total_users_cnt);
$("#myslider_users_cnt div").attr("data-kt-countup", true);
$("#myslider_users_cnt div").text(addCommaForGrands(total_users_cnt));
//TG CHANNELS
fillTGChannels(tg_channels_arr.filter(channel => channel.users > 200), true);
loadMoreChannels_array = tg_channels_arr.filter(channel => channel.users <= 200);
});
}
function mapPreviewCycle(idx) {
$("#map_preview_img").attr("src", "assets/media/map_img/map_gif/pic" + idx + ".jpg");
setTimeout(mapPreviewCycle, 1000, idx % 5 + 1);
}
function initMapPreviewCycle() {
mapPreviewCycle(1);
}