(feat) save the code on front side

This commit is contained in:
b1ek 2024-02-19 02:48:44 +10:00
parent 22a7dc5fd5
commit 5b68507e97
Signed by: blek
GPG Key ID: 14546221E3595D0C
1 changed files with 16 additions and 3 deletions

View File

@ -15,15 +15,28 @@ require(["vs/editor/editor.main"], function () {
/** @type {string[]} */
const supported_langs = get_langs();
let cache_key = 'sandy-cached-code';
const storage = window.localStorage;
let editor = monaco.editor.create(document.getElementById('container'), {
value: '# put code here',
value: storage.getItem(cache_key) ?? '# put code here',
language: init_lang,
theme: 'vs-dark'
});
editor.addListener('didType', () => {
function upd_code() {
window.code = editor.getValue();
});
storage.setItem(cache_key, window.code);
}
function timer_code() {
setTimeout(() => {
timer_code()
upd_code();
}, 500);
}
editor.addListener('didType', () => upd_code);
timer_code();
monaco.languages.getLanguages().forEach(x => {
if (supported_langs.indexOf(x.id) === -1) return