diff --git a/output/js/constants.js b/output/js/constants.js index e2f8b4b..ea946c5 100644 --- a/output/js/constants.js +++ b/output/js/constants.js @@ -35,6 +35,8 @@ export const dom = { export const JOIN_URL_PASTE = "Copied URL to clipboard. Paste into Session app to join"; +export const communityQRCodeURL = (communityID) => `qr-codes/${communityID}.png` + export const COLUMN = { IDENTIFIER: 0, LANGUAGE: 1, NAME: 2, DESCRIPTION: 3, USERS: 4, PREVIEW: 5, @@ -53,6 +55,12 @@ export const COMPARISON = { }; export const ATTRIBUTES = { + ROW: { + IDENTIFIER: 'data-identifier', + PUBLIC_KEY: 'data-pubkey', + HOSTNAME: 'data-hostname', + STAFF_DATA: 'data-staff' + }, SORTING: { ACTIVE: 'data-sort', ASCENDING: 'data-sort-asc', diff --git a/output/main.js b/output/main.js index 28bfbe0..4b48f61 100644 --- a/output/main.js +++ b/output/main.js @@ -16,7 +16,8 @@ // Import magic numbers and data import { dom, COLUMN, COLUMN_LITERAL, COMPARISON, ATTRIBUTES, - columnAscendingByDefault, columnIsSortable, COLUMN_TRANSFORMATION, element, JOIN_URL_PASTE + columnAscendingByDefault, columnIsSortable, COLUMN_TRANSFORMATION, + element, JOIN_URL_PASTE, communityQRCodeURL } from './js/constants.js'; // Hidden communities for transparency. @@ -104,7 +105,7 @@ function displayQRModal(communityID) { } } - dom.details_modal_qr_code().src = `qr-codes/${communityID}.png`; + dom.details_modal_qr_code().src = communityQRCodeURL(communityID); modal.showModal(); } @@ -117,7 +118,7 @@ function addQRModalHandlers() { const rows = dom.tbl_communities_content_rows(); if (!rows) throw new Error("Rows not found"); for (const row of rows) { - const communityID = row.getAttribute('data-identifier'); + const communityID = row.getAttribute(ATTRIBUTES.ROW.IDENTIFIER); row.querySelector('.td_qr_code').addEventListener( 'click', () => displayQRModal(communityID) @@ -150,7 +151,7 @@ function addQRModalHandlers() { /** * @type {string[]} */ - const staff = JSON.parse(this.getAttribute('data-staff')); + const staff = JSON.parse(this.getAttribute(ATTRIBUTES.ROW.STAFF_DATA)); if (staff.length == 0) { alert("No public moderators available for this Community."); return; @@ -159,7 +160,7 @@ function addQRModalHandlers() { copyToClipboard(`@${staffId}`, 'Copied staff ID to clipboard.'); } ) - + for (const anchor of dom.qr_code_buttons()) { // Disable QR code links anchor.setAttribute("href", "#"); @@ -241,8 +242,8 @@ function setLastChecked(last_checked) { function addServerIconInteractions() { const rows = dom.tbl_communities_content_rows(); for (const row of rows) { - const hostname = row.getAttribute('data-hostname'); - const publicKey = row.getAttribute('data-pubkey'); + const hostname = row.getAttribute(ATTRIBUTES.ROW.HOSTNAME); + const publicKey = row.getAttribute(ATTRIBUTES.ROW.PUBLIC_KEY); const serverIcon = row.querySelector('.td_server_icon'); serverIcon.addEventListener('click', () => { alert(`Host: ${hostname}\n\nPublic key:\n${publicKey}`);