From 2f7e26b02b4a8b6374ff3537acf1ba873c2613c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthew=20Yang=20=28=E6=9D=A8=E4=BD=B3=E6=98=8E=29?= Date: Sun, 16 Aug 2026 03:06:17 -0700 Subject: [PATCH] Fix other domains (#7) * Make main compressor capable of other domains * Fix missing bracket * Domain needs to contain port as well * Add decode functionality for other domains --------- Co-authored-by: p2r3 <41925384+p2r3@users.noreply.github.com> --- main.js | 16 +++++++++++++--- standalone.js | 10 ++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index f6d84e2..ba00129 100644 --- a/main.js +++ b/main.js @@ -5,6 +5,15 @@ import { outputAlphabetEmoji } from "./alphabets.js"; +let domain = window.location.hostname; +if (domain !== "ha.mr" && domain !== "www.ha.mr") { + console.log(`This page is intended to be used on the ha.mr domain. You are currently on ${domain}.`); +} +const webPort = window.location.port; +if (webPort && webPort !== "80" && webPort !== "443") { + domain += `:${webPort}`; +} + var settings = { emoji: false, qr: false @@ -116,8 +125,8 @@ function updateOutput () { outputRatioElement.textContent = "Output is the same length as the input"; outputRatioElement.style.color = "gray"; } - outputLinkElement.textContent = `http://ha.mr#${output}`; - outputLinkElement.href = `http://ha.mr#${output}`; + outputLinkElement.textContent = `http://${domain}#${output}`; + outputLinkElement.href = `http://${domain}#${output}`; outputLinkElement.style.color = ""; if (settings.qr) { const correctionLevels = ["L", "M", "Q", "H"]; @@ -125,7 +134,8 @@ function updateOutput () { qrCodeImage.style.display = "inline"; qrCodeCorrectionLevelContainer.style.display = "inline"; - const qrCodeLink = `HTTP://HA.MR/${compress(input, outputAlphabetQR)}`; + const qrCodeDomain = domain.toUpperCase(); + const qrCodeLink = `HTTP://${qrCodeDomain}/${compress(input, outputAlphabetQR)}`; if (!qrCorrectionManuallySet) { const optimalLevel = getOptimalErrorCorrectionLevel(qrCodeLink); diff --git a/standalone.js b/standalone.js index 5c9bc16..55b0f06 100644 --- a/standalone.js +++ b/standalone.js @@ -7,8 +7,10 @@ import { const input = process.argv[2]?.trim(); const alphabetName = process.argv[3]?.trim() || "ascii"; +const command = process.argv[4]?.trim() || "encode"; if (!input) { - console.error(`Usage: hamr [ascii|qr|emoji]`); + console.error(`Usage: hamr [ascii|qr|emoji] {decode|encode}`); + console.error(`The final argument is optional and defaults to "encode".`); process.exit(1); } @@ -19,9 +21,13 @@ if (input.toLowerCase().startsWith("http://ha.mr")) { payload = input.slice(13); } else if (input.toLowerCase().startsWith("ha.mr")) { payload = input.slice(5); +} else if (command === "decode") { + const pos = input.indexOf("#"); + payload = input.slice(pos); + console.log(`Payload: ${payload}`); } -if (payload) { +if (payload || command === "decode") { const isQRCode = input[0] === "/"; payload = payload.slice(1); const useEmoji = Array.from(payload).some(c => !outputAlphabetASCII.includes(c));