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));