From c28463b06da4715a7ee279a419081d021bb9e0cc Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Thu, 24 Aug 2023 00:08:00 +0200 Subject: [PATCH] randomize shared universe names --- package.json | 1 + src/main.ts | 24 +++++++++++++++++------- yarn.lock | 5 +++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 602fa94..12fb1d9 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "tailwind-highlightjs": "^2.0.1", "tailwindcss": "^3.3.3", "tone": "^14.8.49", + "unique-names-generator": "^4.7.1", "vite-plugin-markdown": "^2.1.0", "zifferjs": "^0.0.12", "zzfx": "^1.2.0" diff --git a/src/main.ts b/src/main.ts index ab42b5f..155253d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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() { diff --git a/yarn.lock b/yarn.lock index e2fa885..12b83e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1380,6 +1380,11 @@ uc.micro@^1.0.1, uc.micro@^1.0.5: resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac" integrity sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA== +unique-names-generator@^4.7.1: + version "4.7.1" + resolved "https://registry.yarnpkg.com/unique-names-generator/-/unique-names-generator-4.7.1.tgz#966407b12ba97f618928f77322cfac8c80df5597" + integrity sha512-lMx9dX+KRmG8sq6gulYYpKWZc9RlGsgBR6aoO8Qsm3qvkSJ+3rAymr+TnV8EDMrIrwuFJ4kruzMWM/OpYzPoow== + update-browserslist-db@^1.0.11: version "1.0.11" resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.11.tgz#9a2a641ad2907ae7b3616506f4b977851db5b940"