(feat) save the code on front side
This commit is contained in:
parent
22a7dc5fd5
commit
5b68507e97
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue