Compare commits

...

7 commits
1.0.0 ... main

View file

@ -124,8 +124,9 @@ export function initGalaxy({
onLoggedInChanged onLoggedInChanged
}) { }) {
return new Promise((accept, reject) => { return new Promise((accept, reject) => {
acceptedOrigins = acceptedOrigins ?? ["https://galaxy.click"]; acceptedOrigins = acceptedOrigins?.map(url =>
if (acceptedOrigins.includes(window.origin)) { url.replace(/\/?$/, '/')) ?? ["https://galaxy.click/"];
if (acceptedOrigins.includes(document.referrer.replace(/\/?$/, '/'))) {
// Callbacks to resolve promises // Callbacks to resolve promises
/** @type function(SaveListResponse["list"]):void */ /** @type function(SaveListResponse["list"]):void */
let saveListAccept, let saveListAccept,
@ -143,7 +144,7 @@ export function initGalaxy({
supportsSaveManager, supportsSaveManager,
ignoreApiVersion, ignoreApiVersion,
onLoggedInChanged, onLoggedInChanged,
origin: window.origin, origin: document.referrer.replace(/\/?$/, "/"),
apiVersion: 0, apiVersion: 0,
loggedIn: false, loggedIn: false,
postMessage: function (message) { postMessage: function (message) {
@ -163,7 +164,7 @@ export function initGalaxy({
if (slot in saveCallbacks) { if (slot in saveCallbacks) {
return Promise.reject(`save action for slot ${slot} already in progress.`); 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) => { return new Promise((accept, reject) => {
saveCallbacks[slot] = { accept, reject }; saveCallbacks[slot] = { accept, reject };
}); });
@ -180,7 +181,7 @@ export function initGalaxy({
}; };
window.addEventListener("message", e => { window.addEventListener("message", e => {
if (e.origin === galaxy.origin) { if (e.origin.replace(/\/?$/, '/') === galaxy.origin.replace(/\/?$/, '/')) {
console.log("Received message from Galaxy", e.data); console.log("Received message from Galaxy", e.data);
/** @type GalaxyResponse */ /** @type GalaxyResponse */
const data = e.data; const data = e.data;