fuzzyworld

tools / commit

add support for auto-importing legacy urls

e88c23cc3bba493c66253465b02b2b288825d9c7 · Pavel Safronov · 2025-07-22 22:12:45 -0700 · parents db52355d9198

add support for auto-importing legacy urls
 separator-page/index.html | 53 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 51 insertions(+), 2 deletions(-)

diff --git a/separator-page/index.html b/separator-page/index.html
index 5293c83..d938d37 100644
--- a/separator-page/index.html
+++ b/separator-page/index.html
@@ -7,6 +7,7 @@
     <link rel="icon" id="favicon"
         href="data:image/x-icon;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAgAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//wAA//8AAP//AAD//wAA/n8AAP5/AAD+fwAA/n8AAOAHAADgBwAA/n8AAP5/AAD+fwAA/n8AAP//AAD//wAA" />
     <script src="https://cdn.jsdelivr.net/npm/showdown/dist/showdown.min.js"></script>
+    <script src="https://pavelsafronov.gitlab.io/tools/separator-page/lz-string.js"></script>
     <style>
         body {
             font-family: Arial, sans-serif;
@@ -317,6 +318,52 @@ technically *some* scripts can get your local separator page info
         // Load saved data
         const savedData = JSON.parse(localStorage.getItem(localStorageKey) || "null");
 
+        // Function to handle legacy hash-based data
+        function handleLegacyHashData() {
+            console.debug('Checking for legacy hash data...');
+            console.debug('Current location:', window.location);
+            const hash = window.location.hash;
+            console.debug('Current hash:', hash);
+            if (hash && hash.length > 1) {
+                try {
+                    const base64String = hash.substring(1); // Remove the '#' character
+                    const decompressed = LZString.decompressFromBase64(base64String);
+                    if (decompressed) {
+                        const legacyData = JSON.parse(decompressed);
+                        console.debug('Loaded legacy hash data:', legacyData);
+
+                        // Extract name and description from legacy format
+                        const convertedData = {
+                            title: legacyData.name || "Separator",
+                            description: legacyData.description || "",
+                            icon: null // Will be set below
+                        };
+
+                        // Use the first previous icon or first default icon as fallback
+                        const previousIcons = JSON.parse(localStorage.getItem(previousIconsKey) || "[]");
+                        const fallbackIcon = previousIcons.length > 0 ? previousIcons[0] : defaultIcons[0];
+                        convertedData.icon = fallbackIcon;
+
+                        // Clear the hash and update URL
+                        const newUrl = `${window.location.origin}${window.location.pathname}?tab=${tabId}`;
+                        history.replaceState(null, "", newUrl);
+
+                        // Save the converted data to localStorage
+                        localStorage.setItem(localStorageKey, JSON.stringify(convertedData));
+
+                        return convertedData;
+                    }
+                } catch (error) {
+                    console.warn('Failed to parse legacy hash data:', error);
+                }
+            }
+            console.debug('No legacy hash data found.');
+            return null;
+        }
+
+        // Check for legacy hash data FIRST, before any URL manipulation
+        const legacyData = handleLegacyHashData();
+
         const searchParams = new URLSearchParams(window.location.search);
         if (!searchParams.has("tab")) {
             const newUrl = `${window.location.origin}${window.location.pathname}?tab=${tabId}`;
@@ -330,8 +377,10 @@ technically *some* scripts can get your local separator page info
                 document.title = name;
             }
         }
-
-        if (savedData) {
+        if (legacyData) {
+            renderAll(legacyData);
+            console.debug('Initialized with legacy data:', legacyData);
+        } else if (savedData) {
             renderAll(savedData);
             console.debug('Loaded saved data:', savedData);
         } else {