From b774a84b5171ee358d18ba237712a7bc6de6fa50 Mon Sep 17 00:00:00 2001 From: gravel Date: Tue, 24 Jan 2023 20:49:26 +0000 Subject: [PATCH 1/9] Generate last checked timestamp --- .phpenv | 2 ++ output/main.js | 2 +- sites/index.php | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.phpenv b/.phpenv index 309b041..3c59c08 100644 --- a/.phpenv +++ b/.phpenv @@ -16,4 +16,6 @@ // do not report warnings (timeouts, SSL/TLS errors) error_reporting(E_ALL & ~E_WARNING); + + date_default_timezone_set('UTC'); ?> \ No newline at end of file diff --git a/output/main.js b/output/main.js index 5580094..25ae17b 100644 --- a/output/main.js +++ b/output/main.js @@ -131,7 +131,7 @@ function setLastChecked(last_checked) { const time_passed_in_minutes = Math.floor(time_passed_in_seconds / 60); // time in minutes, rounded down const timestamp_element = dom.last_checked(); - timestamp_element.innerText = `${time_passed_in_minutes} minutes`; + timestamp_element.innerText = `${time_passed_in_minutes} minutes ago`; } /** diff --git a/sites/index.php b/sites/index.php index 2555bb8..24f6478 100644 --- a/sites/index.php +++ b/sites/index.php @@ -42,7 +42,9 @@ (None hidden as JS is off)

- Last checked ago. + Last checked + (UTC) + .

This site is not affiliated with From 66ad8e1dd1bc2b93bc81a30549b7bca2f3593584 Mon Sep 17 00:00:00 2001 From: gravel Date: Tue, 24 Jan 2023 20:52:16 +0000 Subject: [PATCH 2/9] Responsive Join URL display --- output/js/constants.js | 28 +++++++++++++++++++++++++- output/main.js | 20 ++++++++++-------- output/styles2.css | 29 ++++++++++++++++++++++++++- php/utils/server-utils.php | 6 ++++++ sites/+components/tbl_communities.php | 15 +++++++++----- 5 files changed, 83 insertions(+), 15 deletions(-) diff --git a/output/js/constants.js b/output/js/constants.js index f313728..3002622 100644 --- a/output/js/constants.js +++ b/output/js/constants.js @@ -6,7 +6,7 @@ export const dom = { tbl_communities: () => document.getElementById("tbl_communities"), last_checked: () => document.getElementById("last_checked_value"), qr_modal: (communityID) => document.getElementById(`modal_${communityID}`), - join_urls: () => document.getElementsByClassName("td_join_url"), + join_urls: () => document.getElementsByClassName("join_url_container"), servers_hidden: () => document.getElementById("servers_hidden"), snackbar: () => document.getElementById("copy-snackbar") } @@ -57,3 +57,29 @@ export function columnIsNumeric(column) { ].includes(column); } +/** + * Creates an element, and adds attributes and elements to it. + * @param {string} tag - HTML Tag name. + * @param {Object|HTMLElement} args - Array of child elements, may start with props. + * @returns {HTMLElement} + */ +function createElement(tag, ...args) { + const element = document.createElement(tag); + if (args.length === 0) return element; + const propsCandidate = args[0]; + if (typeof propsCandidate !== "string" && !(propsCandidate instanceof Element)) { + // args[0] is not child element or text node + // must be props object + Object.assign(element, propsCandidate); + args.shift(); + } + element.append(...args); + return element; +} + +export const element = new Proxy({}, { + get(_, key) { + return (...args) => createElement(key, ...args) + } +}); + diff --git a/output/main.js b/output/main.js index 25ae17b..0bc0bdb 100644 --- a/output/main.js +++ b/output/main.js @@ -17,7 +17,7 @@ import { dom, COLUMN, COLUMN_LITERAL, COMPARISON, ATTRIBUTES, columnAscendingByDefault, columnIsSortable, columnNeedsCasefold, - columnIsNumeric + columnIsNumeric, element } from './js/constants.js'; // Hidden communities for transparency. @@ -50,12 +50,13 @@ const filteredCommunities = { // This can be achieved with `text-overflow: ellipsis` instead // and generated entirely server-side. -const transformJoinURL = (join_link) => - `${join_link.substring(0, 31)}... - - `.trim(); +const transformJoinURL = (join_link) => { + return element.button({ + textContent: "Copy", + className: "copy_button", + onclick: () => copyToClipboard(join_link) + }); +} function onLoad(timestamp) { setLastChecked(timestamp); @@ -78,7 +79,7 @@ function createJoinLinkButtons() { Array.from(join_URLs).forEach((td_url) => { const a_href = td_url.querySelector('a'); // get first (only) element const join_link = a_href.getAttribute("href"); // get link - td_url.innerHTML = transformJoinURL(join_link); // add interactive content + td_url.append(transformJoinURL(join_link)); // add interactive content }); } @@ -279,6 +280,9 @@ function sortTable(column) { setSortState(table, { ascending, column }); } +// html.js for styling purposes +window.document.documentElement.classList.add("js"); + // Crude way to export from module script due to inline event handlers. // Ideally, all handlers would be attached from JS via addEventListener. Object.assign(window, { diff --git a/output/styles2.css b/output/styles2.css index 40b4309..5d40936 100644 --- a/output/styles2.css +++ b/output/styles2.css @@ -37,7 +37,34 @@ header { white-space: nowrap; } -.copy_button { } +.join_url.nojs_mobile { + display: none; +} + +/* Apply margin against copy button. */ +html.js .join_url { + margin-right: 1em; +} + +@media (max-width: 800px) { + .join_url { + display: none; + } + + /* Show backup link only when button is not available. */ + html:not(.js) .join_url.nojs_mobile { + display: inline; + } +} + +.join_url_container { + display: flex; + flex-direction: row; + align-items: center; + justify-content: space-between; +} + +.copy_button { font-size: inherit } footer { display: flex; diff --git a/php/utils/server-utils.php b/php/utils/server-utils.php index c0e91a3..f6ac141 100644 --- a/php/utils/server-utils.php +++ b/php/utils/server-utils.php @@ -18,6 +18,12 @@ return count($servers); } + function truncate($url, $len) { + return (strlen($url) > $len + 3) + ? substr($url, 0, $len).'...' + : $string; + } + /* * Helper function for reduce_servers */ diff --git a/sites/+components/tbl_communities.php b/sites/+components/tbl_communities.php index a0b5c32..63d4fc5 100644 --- a/sites/+components/tbl_communities.php +++ b/sites/+components/tbl_communities.php @@ -1,4 +1,6 @@ - - - join_link?> - - +

+ join_link, 32)?> + Copy link +
From 6286a4fb98c4421bfbeced272e0bf383f3b77f84 Mon Sep 17 00:00:00 2001 From: gravel Date: Tue, 24 Jan 2023 20:58:30 +0000 Subject: [PATCH 3/9] Fix footer layout --- output/styles2.css | 13 ++++++++++++- sites/index.php | 12 +++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/output/styles2.css b/output/styles2.css index 5d40936..c724190 100644 --- a/output/styles2.css +++ b/output/styles2.css @@ -1,3 +1,12 @@ +html.js .noscript { + display: none; +} + +/* Dead style */ +html:not(.js) .js-only { + display: none; +} + header { display: flex; direction: row; @@ -81,7 +90,9 @@ footer p { } footer nav a { - margin: 0 .5ch; + display: inline-block; + margin: .25em; + white-space: nowrap; } /* */ diff --git a/sites/index.php b/sites/index.php index 24f6478..307070c 100644 --- a/sites/index.php +++ b/sites/index.php @@ -57,13 +57,11 @@ objectionable or illegal content, but you should still proceed with caution.

- +

+ This site works fine without JavaScript. + However, some interactive features are + only available with JS enabled. +