From e16fb553ae8a5aa0019b749c603faeba93de35cb Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sun, 18 Feb 2024 16:09:58 +0000 Subject: [PATCH 1/7] Fix window.origin not being the "parent" document --- galaxy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galaxy.js b/galaxy.js index 251f7f8..0039300 100644 --- a/galaxy.js +++ b/galaxy.js @@ -125,7 +125,7 @@ export function initGalaxy({ }) { return new Promise((accept, reject) => { acceptedOrigins = acceptedOrigins ?? ["https://galaxy.click"]; - if (acceptedOrigins.includes(window.origin)) { + if (acceptedOrigins.includes(document.referrer)) { // Callbacks to resolve promises /** @type function(SaveListResponse["list"]):void */ let saveListAccept, From 5eaa07306113a6d20fb8c1552a14e61d675977a8 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sun, 18 Feb 2024 16:12:47 +0000 Subject: [PATCH 2/7] Update galaxy.js --- galaxy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galaxy.js b/galaxy.js index 0039300..45aa69d 100644 --- a/galaxy.js +++ b/galaxy.js @@ -143,7 +143,7 @@ export function initGalaxy({ supportsSaveManager, ignoreApiVersion, onLoggedInChanged, - origin: window.origin, + origin: document.referrer, apiVersion: 0, loggedIn: false, postMessage: function (message) { From 886c3bbb3a43c3aa29d8b83372715135262b04ab Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sun, 18 Feb 2024 16:27:24 +0000 Subject: [PATCH 3/7] Update galaxy.js --- galaxy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galaxy.js b/galaxy.js index 45aa69d..71ae7a7 100644 --- a/galaxy.js +++ b/galaxy.js @@ -124,7 +124,7 @@ export function initGalaxy({ onLoggedInChanged }) { return new Promise((accept, reject) => { - acceptedOrigins = acceptedOrigins ?? ["https://galaxy.click"]; + acceptedOrigins = acceptedOrigins ?? ["https://galaxy.click/"]; if (acceptedOrigins.includes(document.referrer)) { // Callbacks to resolve promises /** @type function(SaveListResponse["list"]):void */ From dae532627ce633e3777c3d404e6e723ea37195a8 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sun, 18 Feb 2024 16:35:41 +0000 Subject: [PATCH 4/7] Make trailing slashes consistent --- galaxy.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/galaxy.js b/galaxy.js index 71ae7a7..1d7932d 100644 --- a/galaxy.js +++ b/galaxy.js @@ -124,8 +124,9 @@ export function initGalaxy({ onLoggedInChanged }) { return new Promise((accept, reject) => { - acceptedOrigins = acceptedOrigins ?? ["https://galaxy.click/"]; - if (acceptedOrigins.includes(document.referrer)) { + acceptedOrigins = acceptedOrigins.map(url => + url.replace(/\/?$/, '/')) ?? ["https://galaxy.click/"]; + if (acceptedOrigins.includes(document.referrer.replace(/\/?$/, '/'))) { // Callbacks to resolve promises /** @type function(SaveListResponse["list"]):void */ let saveListAccept, @@ -180,7 +181,7 @@ export function initGalaxy({ }; window.addEventListener("message", e => { - if (e.origin === galaxy.origin) { + if (e.origin.replace(/\/?$/, '/') === galaxy.origin.replace(/\/?$/, '/')) { console.log("Received message from Galaxy", e.data); /** @type GalaxyResponse */ const data = e.data; From 2e5e690d4674c4a806f387c7b938b5054e5080a1 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sun, 18 Feb 2024 16:38:56 +0000 Subject: [PATCH 5/7] Update galaxy.js --- galaxy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galaxy.js b/galaxy.js index 1d7932d..0d67282 100644 --- a/galaxy.js +++ b/galaxy.js @@ -124,7 +124,7 @@ export function initGalaxy({ onLoggedInChanged }) { return new Promise((accept, reject) => { - acceptedOrigins = acceptedOrigins.map(url => + acceptedOrigins = acceptedOrigins?.map(url => url.replace(/\/?$/, '/')) ?? ["https://galaxy.click/"]; if (acceptedOrigins.includes(document.referrer.replace(/\/?$/, '/'))) { // Callbacks to resolve promises From 3fdca4b2ae6d5d7fa358209b83a851b63d2fdb1a Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sun, 18 Feb 2024 16:41:36 +0000 Subject: [PATCH 6/7] Update galaxy.js --- galaxy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galaxy.js b/galaxy.js index 0d67282..21d92e2 100644 --- a/galaxy.js +++ b/galaxy.js @@ -144,7 +144,7 @@ export function initGalaxy({ supportsSaveManager, ignoreApiVersion, onLoggedInChanged, - origin: document.referrer, + origin: document.referrer.replace(/\/?$/, "/"), apiVersion: 0, loggedIn: false, postMessage: function (message) { From 97d6da6636a2fc38c14aa893d4b336ccc22314af Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sun, 18 Feb 2024 17:50:53 +0000 Subject: [PATCH 7/7] Fix save action taking data field, not content --- galaxy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galaxy.js b/galaxy.js index 21d92e2..3aac816 100644 --- a/galaxy.js +++ b/galaxy.js @@ -164,7 +164,7 @@ export function initGalaxy({ if (slot in saveCallbacks) { return Promise.reject(`save action for slot ${slot} already in progress.`); } - galaxy.postMessage({ action: "save", slot, content, label }); + galaxy.postMessage({ action: "save", slot, data: content, label }); return new Promise((accept, reject) => { saveCallbacks[slot] = { accept, reject }; });