randomize shared universe names

This commit is contained in:
2023-08-24 00:08:00 +02:00
parent c6a2f5f1a8
commit c28463b06d
3 changed files with 23 additions and 7 deletions

View File

@ -1,3 +1,10 @@
import {
uniqueNamesGenerator,
Config,
adjectives,
colors,
animals,
} from "unique-names-generator";
import { EditorState, Compartment } from "@codemirror/state";
import { ViewUpdate, lineNumbers, keymap } from "@codemirror/view";
import { javascript } from "@codemirror/lang-javascript";
@ -579,13 +586,14 @@ export class Editor {
const universeParam = url.get("universe");
if (universeParam !== null) {
new_universe = JSON.parse(atob(universeParam));
this.loadUniverse("imported", new_universe["universe"]);
const randomName: string = uniqueNamesGenerator({
dictionaries: [adjectives, colors, animals],
});
this.loadUniverse(randomName, new_universe["universe"]);
this.emptyUrl();
}
}
}
console.log(this.universes[this.selected_universe]);
console.log(this.universes["imported"]);
}
get note_buffer() {
@ -615,14 +623,16 @@ export class Editor {
};
share() {
const hashed_table = btoa(JSON.stringify(
{
const hashed_table = btoa(
JSON.stringify({
universe: this.settings.universes[this.selected_universe],
}
));
})
);
const url = new URL(window.location.href);
url.searchParams.set("universe", hashed_table);
window.history.replaceState({}, "", url.toString());
// Copy the text inside the text field
navigator.clipboard.writeText(url.toString());
}
showDocumentation() {