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>
This commit is contained in:
committed by
GitHub
parent
b609b3acf7
commit
2f7e26b02b
@@ -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);
|
||||
|
||||
+8
-2
@@ -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 <link> [ascii|qr|emoji]`);
|
||||
console.error(`Usage: hamr <link> [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));
|
||||
|
||||
Reference in New Issue
Block a user