Refactor JS slightly and add number of hidden communities

pull/7/head
mdPlusPlus 2 years ago
parent 9d5c14d630
commit 3ea03340a3

@ -1,3 +1,5 @@
var numberOfHiddenCommunities = 0;
function onLoad(timestamp) { function onLoad(timestamp) {
setLastChecked(timestamp); setLastChecked(timestamp);
hideBadCommunities(); hideBadCommunities();
@ -6,25 +8,25 @@ function onLoad(timestamp) {
} }
function displayQRModal(communityID) { function displayQRModal(communityID) {
var modalID = "modal_" + communityID; const modalID = "modal_" + communityID;
modal = document.getElementById(modalID); const modal = document.getElementById(modalID);
modal.style.display = "block"; modal.style.display = "block";
} }
function hideQRModal(communityID) { function hideQRModal(communityID) {
var modalID = "modal_" + communityID; const modalID = "modal_" + communityID;
modal = document.getElementById(modalID); const modal = document.getElementById(modalID);
modal.style.display = "none"; modal.style.display = "none";
} }
function createJoinLinkButtons() { function createJoinLinkButtons() {
elements = document.getElementsByClassName("td_join_url"); const elements = document.getElementsByClassName("td_join_url");
Array.from(elements).forEach((td_element) => { Array.from(elements).forEach((td_element) => {
a_href = td_element.getElementsByTagName('a')[0]; // get first (only) <a> element const a_href = td_element.getElementsByTagName('a')[0]; // get first (only) <a> element
join_link = a_href.getAttribute("href"); // get link const join_link = a_href.getAttribute("href"); // get link
button_content = join_link.substring(0, 31) + "...<button class=\"copy_button\" onclick=\"copyToClipboard('" + join_link + "')\">Copy</button>"; const cell_content = join_link.substring(0, 31) + "...<button class=\"copy_button\" onclick=\"copyToClipboard('" + join_link + "')\">Copy</button>";
td_element.innerHTML = button_content; td_element.innerHTML = cell_content;
}); });
} }
@ -46,18 +48,23 @@ function hideBadCommunities() {
// These communities should be checked regularly in case they updated their PySOGS version // These communities should be checked regularly in case they updated their PySOGS version
const legacyCommunitiyIDs = [ const legacyCommunitiyIDs = [
"Ukraine+02bd" "Ukraine+02bd" // https://reccacon.com/view/room/Ukraine
]; ];
testCommunityIDs.forEach(hideElementByID); testCommunityIDs.forEach(hideElementByID);
badCommunityIDs.forEach(hideElementByID); badCommunityIDs.forEach(hideElementByID);
legacyCommunitiyIDs.forEach(hideElementByID); legacyCommunitiyIDs.forEach(hideElementByID);
const summary = document.getElementById("td_summary");
summaryNew = summary.innerHTML + " (" + numberOfHiddenCommunities + " hidden)";
summary.innerHTML = summaryNew;
} }
function hideElementByID(id) { function hideElementByID(id) {
element = document.getElementById(id); const element = document.getElementById(id);
if(element != null) { if(element != null) {
element.remove(); element.remove();
numberOfHiddenCommunities++;
} }
} }
@ -66,11 +73,11 @@ function copyToClipboard(text) {
} }
function setLastChecked(timestamp) { function setLastChecked(timestamp) {
now = Math.floor(Date.now() / 1000); // timestamp in seconds const now = Math.floor(Date.now() / 1000); // timestamp in seconds
time_passed_in_seconds = now - timestamp; const time_passed_in_seconds = now - timestamp;
time_passed_in_minutes = Math.floor(time_passed_in_seconds / 60); // time in minutes, rounded down const time_passed_in_minutes = Math.floor(time_passed_in_seconds / 60); // time in minutes, rounded down
td_element = document.getElementById("td_last_checked"); const td_last_checked = document.getElementById("td_last_checked");
td_element.innerHTML = "Last checked " + time_passed_in_minutes + " minutes ago."; td_last_checked.innerHTML = "Last checked " + time_passed_in_minutes + " minutes ago.";
} }
function sortTable(n) { function sortTable(n) {

Loading…
Cancel
Save