From ff2d6c14b26dbef907e7e792d5a66dd15cd680d2 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Tue, 31 Aug 2021 17:13:50 -0400 Subject: [PATCH] Use fragments instead of query params Permalinks now just stick the base64 string into the fragment portion of the URL, rather than using a query parameter. This should reduce spam in the server logs, and also keep scenes more private. --- macrovision.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/macrovision.js b/macrovision.js index 94cbe3c1..1bb69032 100644 --- a/macrovision.js +++ b/macrovision.js @@ -3002,7 +3002,15 @@ document.addEventListener("DOMContentLoaded", () => { unitSelector.addEventListener("input", selectNewUnit); - param = new URL(window.location.href).searchParams.get("scene"); + param = window.location.hash; + + // we now use the fragment for links, but we should still support old stuff: + + if (param.length > 0) { + param = param.substring(1); + } else { + param = new URL(window.location.href).searchParams.get("scene"); + } document.querySelector("#world").addEventListener("mousedown", e => { // only middle mouse clicks @@ -4418,7 +4426,7 @@ function b64DecodeUnicode(str) { function linkScene() { loc = new URL(window.location); - const link = loc.protocol + "//" + loc.host + loc.pathname + "?scene=" + b64EncodeUnicode(JSON.stringify(exportScene())); + const link = loc.protocol + "//" + loc.host + loc.pathname + "#" + b64EncodeUnicode(JSON.stringify(exportScene())); window.history.replaceState(null, "Macrovision", link); try { navigator.clipboard.writeText(link);