From 25867c2887776ecc52ddbec741faf7f1ae05d6dd Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Tue, 8 Oct 2024 12:35:26 +0800 Subject: feat: add search params 'content' for tutorial --- src/editor.mjs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/editor.mjs b/src/editor.mjs index 866237a..f0b4af0 100644 --- a/src/editor.mjs +++ b/src/editor.mjs @@ -7,6 +7,7 @@ import { shiftByWindow } from './utils.mjs' // Set up Containers {{{ +const url = new URL(window.location) const context = document.querySelector('[data-mode]') const dumbyContainer = document.querySelector('.DumbyMap') const textArea = document.querySelector('.editor textarea') @@ -134,6 +135,7 @@ const editor = new EasyMDE({ action: () => { const state = { content: editor.value() } window.location.hash = encodeURIComponent(JSON.stringify(state)) + window.location.search = '' navigator.clipboard.writeText(window.location.href) window.alert('URL updated in address bar, you can save current page as bookmark') } @@ -239,17 +241,19 @@ const getContentFromHash = hash => { const state = getStateFromHash(hash) return state.content } +const contentFromHash = getContentFromHash(window.location.hash) -const initialState = getStateFromHash(window.location.hash) -window.location.hash = '' -const contentFromHash = initialState.content - -// Seems like autosave would overwrite initialValue, set content from hash here -if (contentFromHash) { +if (url.searchParams.get('content') === 'tutorial') { + console.log('tutorial') + editor.value(defaultContent) +} else if (contentFromHash) { + // Seems like autosave would overwrite initialValue, set content from hash here editor.cleanup() editor.value(contentFromHash) } +window.location.hash = '' + // }}} // Set up logic about editor content {{{ -- cgit v1.2.3-70-g09d2