fuzzyworld

tools / commit

Separator page: import a tab's data from the old gitlab.io address

c4975b4a182e7c32ff65c0c5f072e4deacceaf94 · Pavel Safronov · 2026-10-27 16:42:07 -0700 · parents 3cf724510075

Separator page: import a tab's data from the old gitlab.io address

The old redirect page passes the tab's record in #migrate=..., accepted
only when arriving from pavelsafronov.gitlab.io.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
 separator-page/index.html | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 separator-page/readme.md  |  4 ++++
 2 files changed, 50 insertions(+)

diff --git a/separator-page/index.html b/separator-page/index.html
index 46e74b2..4acb912 100644
--- a/separator-page/index.html
+++ b/separator-page/index.html
@@ -310,6 +310,52 @@ technically *some* scripts can get your local separator page info
             "./icons/template-icon-13.png"
         ];
 
+        // Import a tab from the old address (pavelsafronov.gitlab.io). Browsers keep storage per site, so the
+        // redirect page there reads this tab's data and passes it along as #migrate=<URI-encoded JSON>.
+        // The payload is only trusted when we arrive from that site, because the description is rendered as HTML.
+        function handleMigrationData() {
+            const prefix = "#migrate=";
+            if (!window.location.hash.startsWith(prefix)) {
+                return;
+            }
+            const cleanUrl = `${window.location.origin}${window.location.pathname}?tab=${tabId}`;
+            try {
+                const cameFromOldSite = document.referrer.startsWith("https://pavelsafronov.gitlab.io/");
+                if (!cameFromOldSite) {
+                    console.warn('Ignoring migration data: not from the old site. Referrer:', document.referrer);
+                    return;
+                }
+                const payload = JSON.parse(decodeURIComponent(window.location.hash.substring(prefix.length)));
+                const toCurrentSite = (icon) => {
+                    // Built-in icons were stored as absolute URLs on the old site, where they no longer exist.
+                    const match = typeof icon === "string" && icon.match(/\/separator-page\/icons\/(template-icon-\d+\.png)$/);
+                    return match ? new URL(`icons/${match[1]}`, window.location.href).href : icon;
+                };
+
+                // Keep the user's icon history too, behind whatever this site already has.
+                if (Array.isArray(payload.previousIcons)) {
+                    const existing = JSON.parse(localStorage.getItem(previousIconsKey) || "[]");
+                    const merged = [...existing, ...payload.previousIcons.map(toCurrentSite)];
+                    const unique = [...new Set(merged)].slice(0, maxPreviousIcons);
+                    localStorage.setItem(previousIconsKey, JSON.stringify(unique));
+                }
+
+                // Never overwrite a tab that already exists here.
+                const data = payload.data;
+                if (data && String(payload.tab) === tabId && !localStorage.getItem(localStorageKey)) {
+                    data.icon = toCurrentSite(data.icon);
+                    localStorage.setItem(localStorageKey, JSON.stringify(data));
+                    console.debug('Imported tab from the old site:', data);
+                }
+            } catch (error) {
+                console.warn('Failed to import migration data:', error);
+            } finally {
+                history.replaceState(null, "", cleanUrl);
+            }
+        }
+
+        handleMigrationData();
+
         // Load saved data
         const savedData = JSON.parse(localStorage.getItem(localStorageKey) || "null");
 
diff --git a/separator-page/readme.md b/separator-page/readme.md
index 1513b3c..e0c711e 100644
--- a/separator-page/readme.md
+++ b/separator-page/readme.md
@@ -16,3 +16,7 @@ This screenshot shows how to add the separator page to your bookmarks, so you ca
 1. Create a bookmark to this page in your browser: `https://apps.fuzzyworld.net/tools/separator-page/index.html?name=%s`
 2. Assign the bookmark a Keyword, for example `~`
 3. Navigate to `~ Project` in your browser to get a new separator page with the title "Project"
+
+## Moving from the old address
+
+The page used to live at `pavelsafronov.gitlab.io/tools/separator-page/`. Browsers keep local storage per site, so the new address can't see the old data directly. The old address now has a redirect page that, for a separator tab (`?tab=<id>`), reads that tab's title, text and icon (plus the icon history) from its local storage and passes them in the URL (`#migrate=...`). This page imports them once, only when the visitor arrives from the old address and the tab doesn't already exist here. Open each old tab once, in the same browser, to bring it over.