surplus-dev 2 лет назад
Родитель
Сommit
de4e5f37d1

+ 2 - 0
app.py

@@ -347,6 +347,8 @@ app.route('/list/document/short/<int:arg_num>', defaults = { 'tool' : 'short_pag
 
 app.route('/list/file')(list_image_file)
 app.route('/list/file/<int:arg_num>')(list_image_file)
+app.route('/list/image', defaults = { 'do_type' : 1 })(list_image_file)
+app.route('/list/image/int:arg_num', defaults = { 'do_type' : 1 })(list_image_file)
 
 app.route('/list/admin')(list_admin)
 

+ 1 - 1
emergency_tool.py

@@ -200,7 +200,7 @@ elif what_i_do == '19':
 
         ok += [os.system('git remote rm origin')]
         ok += [os.system('git remote add origin https://github.com/opennamu/opennamu.git')]
-        ok += [os.system('git fetch origin ' + up_data)]
+        ok += [os.system('git fetch origin')]
         ok += [os.system('git reset --hard origin/' + up_data)]
         if (ok[0] and ok[1] and ok[2] and ok[3]) != 0:
             print('Error : update failed')

+ 1 - 1
lang/en-US.json

@@ -272,7 +272,7 @@
                 "bbs_comment_acl" : "BBS ACL to write comment",
         "_comment_" : "Edit",
             "load" : "Load another document",
-            "turn_off_monaco" : "Turn off monaco editor",
+            "turn_off_monaco" : "Turn on/off monaco editor",
         "_comment_" : "Render",
             "toc" : "TOC",
             "category" : "Category",

+ 1 - 1
lang/ko-KR.json

@@ -484,7 +484,7 @@
     "topic_normal": "일반",
     "topic_stop": "중지",
     "topic_close": "닫힘",
-    "turn_off_monaco": "모나코 에디터 끄기",
+    "turn_off_monaco": "모나코 에디터 켜기/끄기",
     "topic_agree": "토론 합의 완료",
     "user_css_warning": "만약 사용하다가 문제가 생기면 여기로 접속하세요.",
     "main_css_warning": "만약 사용하다가 문제가 생기면 이머전시 툴을 사용하세요.",

+ 15 - 21
route/edit.py

@@ -49,32 +49,26 @@ def edit_editor(curs, ip, data_main = '', do_type = 'edit', addon = ''):
             
     p_text = html.escape(sql_d[0][0]) if sql_d and sql_d[0][0] != '' else load_lang('default_edit_help')
     
-    monaco_editor_top += '<a href="javascript:do_monaco_to_textarea(); opennamu_do_editor_temp_save();">(' + load_lang('load_temp_save') + ')</a> <a href="javascript:opennamu_do_editor_temp_save_load();">(' + load_lang('load_temp_save_load') + ')</a> '
+    monaco_editor_top += '<a href="javascript:opennamu_do_editor_temp_save();">(' + load_lang('load_temp_save') + ')</a> <a href="javascript:opennamu_do_editor_temp_save_load();">(' + load_lang('load_temp_save_load') + ')</a> '
+    monaco_editor_top += '<a href="javascript:opennamu_edit_turn_off_monaco();">(' + load_lang('turn_off_monaco') + ')</a>'
+
+    add_get_file = '''
+        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.41.0/min/vs/editor/editor.main.min.css" integrity="sha512-MFDhxgOYIqLdcYTXw7en/n5BshKoduTitYmX8TkQ+iJOGjrWusRi8+KmfZOrgaDrCjZSotH2d1U1e/Z1KT6nWw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
+        <script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.41.0/min/vs/loader.min.js" integrity="sha512-A+6SvPGkIN9Rf0mUXmW4xh7rDvALXf/f0VtOUiHlDUSPknu2kcfz1KzLpOJyL2pO+nZS13hhIjLqVgiQExLJrw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
+    '''
+    
+    darkmode = flask.request.cookies.get('main_css_darkmode', '0')
+    monaco_thema = 'vs-dark' if darkmode == '1' else ''
+    
+    add_script = 'do_monaco_init("' + monaco_thema + '");'
     
     monaco_on = get_main_skin_set(curs, flask.session, 'main_css_monaco', ip)
     if monaco_on == 'use':
         editor_display = 'style="display: none;"'
-        add_get_file = '''
-            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.41.0/min/vs/editor/editor.main.min.css" integrity="sha512-MFDhxgOYIqLdcYTXw7en/n5BshKoduTitYmX8TkQ+iJOGjrWusRi8+KmfZOrgaDrCjZSotH2d1U1e/Z1KT6nWw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
-            <script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.41.0/min/vs/loader.min.js" integrity="sha512-A+6SvPGkIN9Rf0mUXmW4xh7rDvALXf/f0VtOUiHlDUSPknu2kcfz1KzLpOJyL2pO+nZS13hhIjLqVgiQExLJrw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
-        '''
-
-        monaco_editor_top += '<a href="javascript:opennamu_edit_turn_off_monaco();">(' + load_lang('turn_off_monaco') + ')</a>'
-        
-        if flask.request.cookies.get('main_css_darkmode', '0') == '1':
-            monaco_thema = 'vs-dark'
-        else:
-            monaco_thema = ''
-        
-        add_script = 'do_monaco_init("' + monaco_thema + '");'
     else:
         monaco_display = 'style="display: none;"'
-        add_script = 'opennamu_edit_turn_off_monaco();'
 
-    if do_type == 'edit':
-        textarea_size = 'opennamu_textarea_500'
-    else:
-        textarea_size = 'opennamu_textarea_100'
+    textarea_size = 'opennamu_textarea_500' if do_type == 'edit' else 'opennamu_textarea_100'
 
     return add_get_file + '''
         <textarea style="display: none;" id="opennamu_edit_origin" name="doc_data_org">''' + html.escape(data_main) + '''</textarea>
@@ -97,8 +91,8 @@ def edit_editor(curs, ip, data_main = '', do_type = 'edit', addon = ''):
             ''' + add_script + '''
         </script>
                         
-        <button id="opennamu_save_button" type="submit" onclick="do_monaco_to_textarea(); do_stop_exit_release();">''' + load_lang('send') + '''</button>
-        <button id="opennamu_preview_button" type="button" onclick="do_monaco_to_textarea(); opennamu_do_editor_preview();">''' + load_lang('preview') + '''</button>
+        <button id="opennamu_save_button" type="submit" onclick="do_stop_exit_release();">''' + load_lang('send') + '''</button>
+        <button id="opennamu_preview_button" type="button" onclick="opennamu_do_editor_preview();">''' + load_lang('preview') + '''</button>
         <hr class="main_hr">
 
         <div id="opennamu_preview_area"></div>

+ 50 - 7
route/list_image_file.py

@@ -1,19 +1,62 @@
 from .tool.func import *
 
-def list_image_file(arg_num = 1):
+def list_image_file(arg_num = 1, do_type = 0):
     with get_db_connect() as conn:
         curs = conn.cursor()
 
         sql_num = (arg_num * 50 - 50) if arg_num * 50 > 0 else 0
 
-        list_data = '<ul class="opennamu_ul">'
+        list_data = ''
+        if do_type == 0:
+            list_data += '<a href="/list/image">(' + load_lang('image') + ')</a>'
+        else:
+            list_data += '<a href="/list/file">(' + load_lang('normal') + ')</a>'
+        
+        list_data += '<hr class="main_hr">'
 
-        curs.execute(db_change("select title from data where title like 'file:%' limit ?, 50"), [sql_num])
-        data_list = curs.fetchall()
-        for data in data_list:
-            list_data += '<li><a href="/w/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a></li>'
+        if do_type == 1:
+            render_data = ''
+            sub_data = ''
+            count = 0
 
-        list_data += next_fix('/list/file/', arg_num, data_list)
+            curs.execute(db_change("select title from data where title like 'file:%' limit ?, 50"), [sql_num])
+            data_list = curs.fetchall()
+            for data in data_list:
+                if count != 0 and count % 4 == 0:
+                    render_data += '||\n'
+                    render_data += sub_data + '||\n'
+                    
+                    sub_data = ''
+
+                render_data += '|| [[' + data[0] + ']] '
+                sub_data += '|| [[:' + data[0] + ']] '
+                count += 1
+
+            if render_data != '':
+                render_data += '||\n'
+                render_data += sub_data + '||'
+
+            end_data = render_set(
+                doc_name = '',
+                doc_data = render_data,
+                data_type = 'view',
+                markup = 'namumark'
+            )
+            list_data += end_data
+        else:
+            list_data += '<ul class="opennamu_ul">'
+
+            curs.execute(db_change("select title from data where title like 'file:%' limit ?, 50"), [sql_num])
+            data_list = curs.fetchall()
+            for data in data_list:
+                list_data += '<li><a href="/w/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a></li>'
+
+            list_data += '</ul>'
+
+        if do_type == 0:
+            list_data += next_fix('/list/file/', arg_num, data_list)
+        else:
+            list_data += next_fix('/list/image/', arg_num, data_list)
 
         return easy_minify(flask.render_template(skin_check(),
             imp = [load_lang('image_file_list'), wiki_set(), wiki_custom(), wiki_css([0, 0])],

+ 13 - 17
route/login_login.py

@@ -22,27 +22,23 @@ def login_login_2():
 
             user_agent = flask.request.headers.get('User-Agent', '')
             user_id = flask.request.form.get('id', '')
-            user_data = {}
+            user_pw = flask.request.form.get('pw', '')
 
-            curs.execute(db_change(
-                'select name, data from user_set where id = ? and (name = "pw" or name = "encode")'
-            ), [user_id])
-            sql_data = curs.fetchall()
-            if not sql_data:
+            curs.execute(db_change("select data from user_set where id = ? and name = 'pw'"), [user_id])
+            db_data = curs.fetchall()
+            if not db_data:
                 return re_error('/error/2')
-
-            for i in sql_data:
-                user_data[i[0]] = i[1]
-
-            if len(user_data) < 2:
+            else:
+                db_user_pw = db_data[0][0]
+                
+            curs.execute(db_change("select data from user_set where id = ? and name = 'encode'"), [user_id])
+            db_data = curs.fetchall()
+            if not db_data:
                 return re_error('/error/2')
+            else:
+                db_user_encode = db_data[0][0]
 
-            if pw_check(
-                flask.request.form.get('pw', ''),
-                user_data['pw'],
-                user_data['encode'],
-                user_id
-            ) != 1:
+            if pw_check(user_pw, db_user_pw, db_user_encode, user_id) != 1:
                 if not 'login_count' in flask.session:
                     flask.session['login_count'] = 1
                 else:

+ 2 - 6
route/login_login_2fa.py

@@ -25,6 +25,7 @@ def login_login_2fa_2():
 
             user_agent = flask.request.headers.get('User-Agent', '')
             user_id = flask.session['login_id']
+            user_pw = flask.request.form.get('pw', '')
 
             curs.execute(db_change('select data from user_set where name = "2fa_pw" and id = ?'), [user_id])
             user_1 = curs.fetchall()
@@ -33,12 +34,7 @@ def login_login_2fa_2():
                 user_1 = user_1[0][0]
                 user_2 = curs.fetchall()[0][0]
 
-                pw_check_d = pw_check(
-                    flask.request.form.get('pw', ''),
-                    user_1,
-                    user_2,
-                    user_id
-                )
+                pw_check_d = pw_check(user_pw, user_1, user_2, user_id)
                 if pw_check_d != 1:
                     return re_error('/error/10')
 

+ 2 - 6
route/login_login_2fa_email.py

@@ -25,6 +25,7 @@ def login_login_2fa_email_2():
 
             user_agent = flask.request.headers.get('User-Agent', '')
             user_id = flask.session['b_id']
+            user_pw = flask.request.form.get('pw', '')
 
             curs.execute(db_change('select data from user_set where name = "2fa_pw" and id = ?'), [user_id])
             user_1 = curs.fetchall()
@@ -33,12 +34,7 @@ def login_login_2fa_email_2():
                 user_1 = user_1[0][0]
                 user_2 = curs.fetchall()[0][0]
 
-                pw_check_d = pw_check(
-                    flask.request.form.get('pw', ''),
-                    user_1,
-                    user_2,
-                    user_id
-                )
+                pw_check_d = pw_check(user_pw, user_1, user_2, user_id)
                 if pw_check_d != 1:
                     return re_error('/error/10')
 

+ 1 - 1
route/main_func_error_404.py

@@ -11,4 +11,4 @@ def main_func_error_404(e = ''):
             db_data = curs.fetchall()
             db_data = db_data[0][0] if db_data and db_data[0][0] != '' else 'FrontPage'
             
-            return '<script>window.location.href = "/w/' + url_pas(db_data) + '";</script>'
+            return redirect('/w/' + url_pas(db_data))

+ 1 - 1
route/main_sys_update.py

@@ -24,7 +24,7 @@ def main_sys_update():
 
                 ok += [os.system('git remote rm origin')]
                 ok += [os.system('git remote add origin https://github.com/opennamu/opennamu.git')]
-                ok += [os.system('git fetch origin ' + up_data)]
+                ok += [os.system('git fetch origin')]
                 ok += [os.system('git reset --hard origin/' + up_data)]
                 if (ok[0] and ok[1] and ok[2] and ok[3]) == 0:
                     return redirect('/restart')

+ 2 - 1
route/recent_change.py

@@ -103,7 +103,7 @@ def recent_change(name = '', tool = '', num = 1, set_type = 'normal'):
                         data_list += curs.fetchall()
                 else:
                     if set_type != 'normal':
-                        curs.execute(db_change('select id, title, date, ip, send, leng, hide from history where type = ? order by date desc limit ?, 50'), [sql_num])
+                        curs.execute(db_change('select id, title, date, ip, send, leng, hide from history where type = ? order by date desc limit ?, 50'), [set_type, sql_num])
                     else:
                         curs.execute(db_change('select id, title, date, ip, send, leng, hide from history order by date desc limit ?, 50'), [sql_num])
 
@@ -167,6 +167,7 @@ def recent_change(name = '', tool = '', num = 1, set_type = 'normal'):
                 </table>
             '''
 
+            set_type = 'edit' if set_type == '' else set_type
             if tool == 'history':
                 div = '' + \
                     ' '.join(['<a href="/history_page/1/' + for_a[0] + '/' + url_pas(name) + '">(' + for_a[1] + ')</a> ' for for_a in option_list]) + \

+ 13 - 38
route/tool/func.py

@@ -633,35 +633,19 @@ def set_init():
         curs.execute(db_change("select html from html_filter where kind = 'email'"))
         if not curs.fetchall():
             for i in ['naver.com', 'gmail.com', 'daum.net', 'kakao.com']:
-                curs.execute(db_change(
-                    "insert into html_filter (html, kind, plus, plus_t) values (?, 'email', '', '')"
-                ), [i])
+                curs.execute(db_change("insert into html_filter (html, kind, plus, plus_t) values (?, 'email', '', '')"), [i])
 
         curs.execute(db_change("select html from html_filter where kind = 'extension'"))
         if not curs.fetchall():
             for i in ['jpg', 'jpeg', 'png', 'gif', 'webp']:
-                curs.execute(db_change(
-                    "insert into html_filter (html, kind, plus, plus_t) values (?, 'extension', '', '')"
-                ), [i])
+                curs.execute(db_change("insert into html_filter (html, kind, plus, plus_t) values (?, 'extension', '', '')"), [i])
 
-        curs.execute(db_change(
-            'select data from other ' + \
-            'where name = "smtp_server" or name = "smtp_port" or name = "smtp_security"'
-        ))
+        curs.execute(db_change('select data from other where name = "smtp_server" or name = "smtp_port" or name = "smtp_security"'))
         if not curs.fetchall():
-            for i in [
-                ['smtp_server', 'smtp.gmail.com'],
-                ['smtp_port', '587'], 
-                ['smtp_security', 'starttls']
-            ]:
+            for i in [['smtp_server', 'smtp.gmail.com'], ['smtp_port', '587'], ['smtp_security', 'starttls']]:
                 curs.execute(db_change("insert into other (name, data, coverage) values (?, ?, '')"), [i[0], i[1]])
 
-        curs.execute(db_change('insert into html_filter (html, kind, plus, plus_t) values (?, ?, ?, ?)'), [
-            r'(?:[^A-Za-zㄱ-힣0-9])',
-            'name',
-            '',
-            ''
-        ])
+        curs.execute(db_change('insert into html_filter (html, kind, plus, plus_t) values (?, ?, ?, ?)'), [r'(?:[^A-Za-zㄱ-힣0-9])', 'name', '', ''])
 
 # Func-simple
 ## Func-simple-without_DB
@@ -900,24 +884,15 @@ def pw_check(data, data2, type_d = 'no', id_d = ''):
         curs.execute(db_change('select data from other where name = "encode"'))
         db_data = curs.fetchall()
         load_set_data = db_data[0][0] if db_data and db_data[0][0] != '' else 'sha3'
-        set_data = db_data[0][0] if db_data and db_data[0][0] != '' else 'sha3'
         
+        set_data = load_set_data
         if type_d != 'no':
-            if type_d == '':
-                set_data = 'sha3'
-            else:
-                set_data = type_d
+            set_data = 'sha3' if type_d == '' else type_d
 
         re_data = 1 if pw_encode(data, set_data) == data2 else 0
         if load_set_data != set_data and re_data == 1 and id_d != '':
-            curs.execute(db_change("update user_set set data = ? where id = ? and name = 'pw'"), [
-                pw_encode(data), 
-                id_d
-            ])
-            curs.execute(db_change("update user_set set data = ? where id = ? and name = 'encode'"), [
-                load_set_data, 
-                id_d
-            ])
+            curs.execute(db_change("update user_set set data = ? where id = ? and name = 'pw'"), [pw_encode(data), id_d])
+            curs.execute(db_change("update user_set set data = ? where id = ? and name = 'encode'"), [load_set_data, id_d])
 
         return re_data
         
@@ -1026,7 +1001,7 @@ def wiki_css(data):
     data_css = ''
     data_css_add = ''
 
-    data_css_ver = '185'
+    data_css_ver = '186'
     data_css_ver = '.cache_v' + data_css_ver
 
     if 'main_css' in global_wiki_set:
@@ -1293,7 +1268,7 @@ def load_skin(data = '', set_n = 0, default = 0):
     return skin_return_data
 
 # Func-markup
-def render_set(doc_name = '', doc_data = '', data_type = 'view', data_in = '', doc_acl = ''):
+def render_set(doc_name = '', doc_data = '', data_type = 'view', data_in = '', doc_acl = '', markup = ''):
     with get_db_connect() as conn:
         curs = conn.cursor()
 
@@ -1329,7 +1304,7 @@ def render_set(doc_name = '', doc_data = '', data_type = 'view', data_in = '', d
                 if db_data and db_data[0][0] != '':
                     render_lang_data['category'] = db_data[0][0]
 
-                get_class_render = class_do_render(conn, render_lang_data).do_render(doc_name, doc_data, data_type, data_in)
+                get_class_render = class_do_render(conn, render_lang_data, markup).do_render(doc_name, doc_data, data_type, data_in)
                 
                 if 'include' in get_class_render[2]:
                     for_a = 0
@@ -1344,7 +1319,7 @@ def render_set(doc_name = '', doc_data = '', data_type = 'view', data_in = '', d
                         if acl_result == 0:
                             include_regex = re.compile('<div id="' + include_data[0] + '"><\\/div>')
                             if re.search(include_regex, get_class_render[0]):
-                                include_data_render = class_do_render(conn, render_lang_data).do_render(include_data[1], include_data[2], data_type, include_data[0] + data_in)
+                                include_data_render = class_do_render(conn, render_lang_data, markup).do_render(include_data[1], include_data[2], data_type, include_data[0] + data_in)
                                 if len(include_data) > 3:
                                     include_data_render[0] = '<div id="' + include_data[0] + '" ' + include_data[3] + '>' + include_data_render[0] + '</div>'
                                 else:

+ 3 - 2
route/tool/func_render.py

@@ -5,7 +5,7 @@ from .func_render_namumark import class_do_render_namumark
 # 커스텀 마크 언젠간 다시 추가 예정
 
 class class_do_render:
-    def __init__(self, conn, lang_data = {}):
+    def __init__(self, conn, lang_data = {}, markup = ''):
         self.conn = conn
 
         if lang_data == '{}':
@@ -15,6 +15,7 @@ class class_do_render:
             }
 
         self.lang_data = lang_data
+        self.markup = markup
 
     def do_render(self, doc_name, doc_data, data_type, data_in):
         curs = self.conn.cursor()
@@ -26,7 +27,7 @@ class class_do_render:
         
         data_in = (data_in + '_') if data_in != '' else ''
         doc_set['doc_include'] = data_in
-        rep_data = ''
+        rep_data = self.markup
 
         if rep_data == '' and doc_name != '':
             curs.execute(db_change("select set_data from data_set where doc_name = ? and set_name = 'document_markup'"), [doc_name])

+ 1 - 3
route/topic.py

@@ -123,9 +123,7 @@ def topic(topic_num = 0, do_type = '', doc_name = 'Test'):
             name_display = 'display: none;' if topic_num != '0' else ''
 
             shortcut = '<div class="opennamu_thread_shortcut" id="thread_shortcut">'
-            curs.execute(db_change(
-                "select id from topic where code = ? order by id + 0 asc"
-            ), [topic_num])
+            curs.execute(db_change("select id from topic where code = ? order by id + 0 asc"), [topic_num])
             db_data = curs.fetchall()
             for for_a in db_data:
                 shortcut += '<a href="#' + for_a[0] + '">#' + for_a[0] + '</a> '

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "beta" : {
-        "r_ver" : "v3.4.6-RC5-dev47",
+        "r_ver" : "v3.4.6-RC5-dev51",
         "c_ver" : "3500373",
         "s_ver" : "3500112"
     }

+ 34 - 26
views/main_css/js/route/editor.js

@@ -2,9 +2,8 @@
 
 function do_insert_data(data) {
     const name = 'opennamu_edit_textarea';
-    const monaco_name = 'opennamu_monaco_editor';
 
-    if(!document.getElementById(monaco_name)) {
+    if(get_select_editor() === 'textarea') {
         // https://stackoverflow.com/questions/11076975/insert-text-into-textarea-at-cursor-position-javascript
         if(document.selection) {
             document.getElementById(name).focus();
@@ -41,24 +40,11 @@ function do_insert_data(data) {
 // 아직 개편이 더 필요함
 function do_paste_image() {
     const name = 'opennamu_edit_textarea';
-    const monaco_name = 'opennamu_monaco_editor';
 
     window.addEventListener('DOMContentLoaded', async function() {
         let set = await opennamu_get_main_skin_set("main_css_image_paste");
         if(set === 'use') {
-            let textarea;
-            if(
-                document.getElementById(monaco_name) !== null &&
-                document.getElementById(monaco_name) !== undefined
-            ) {
-                textarea = document.getElementById(monaco_name);
-            } else {
-                textarea = document.getElementById(name);
-            }
-
-            if(textarea) {
-                textarea.addEventListener("paste", pasteListener);
-            }
+            document.getElementById(name).addEventListener("paste", pasteListener);
         }
     });
 }
@@ -127,7 +113,7 @@ function pasteListener(e) {
 
 function do_stop_exit() {
     window.onbeforeunload = function() {
-        do_monaco_to_textarea();
+        do_sync_monaco_and_textarea();
 
         let data = document.getElementById('opennamu_edit_textarea').value;
         let origin = document.getElementById('opennamu_edit_origin').value;
@@ -138,22 +124,44 @@ function do_stop_exit() {
 }
 
 function do_stop_exit_release() {
+    do_sync_monaco_and_textarea();
+    
     window.onbeforeunload = function () {}
 }
 
 function opennamu_edit_turn_off_monaco() {
-    do_monaco_to_textarea();
-    
-    document.getElementById('opennamu_edit_textarea').style.display = 'block';
-    document.getElementById('opennamu_monaco_editor').style.display = 'none';
-    document.getElementById('opennamu_monaco_editor').remove();
+    do_sync_monaco_and_textarea();
+
+    if(get_select_editor() === 'textarea') {
+        document.getElementById('opennamu_edit_textarea').style.display = 'none';
+        document.getElementById('opennamu_monaco_editor').style.display = 'block';
+    } else {
+        document.getElementById('opennamu_edit_textarea').style.display = 'block';
+        document.getElementById('opennamu_monaco_editor').style.display = 'none';
+    }
 }
 
 function do_monaco_to_textarea() {
-    if(document.getElementById('opennamu_monaco_editor')) {
-        try {
-            document.getElementById('opennamu_edit_textarea').value = window.editor.getValue();
-        } catch(e) {}
+    document.getElementById('opennamu_edit_textarea').value = window.editor.getValue();
+}
+
+function do_textarea_to_manaco() {
+    window.editor.setValue(document.getElementById('opennamu_edit_textarea').value);
+}
+
+function get_select_editor() {
+    if(document.getElementById('opennamu_monaco_editor').style.display === 'none') {
+        return 'textarea'
+    } else {
+        return 'monaco'
+    }
+}
+
+function do_sync_monaco_and_textarea(select = '') {
+    if(select === 'textarea_to_monaco' || get_select_editor() === 'textarea') {
+        do_textarea_to_manaco();
+    } else {
+        do_monaco_to_textarea();
     }
 }
 

+ 3 - 5
views/main_css/js/route/editor_sub.js

@@ -1,4 +1,5 @@
 function opennamu_do_editor_preview() {
+    do_sync_monaco_and_textarea();
     var input = document.querySelector('#opennamu_edit_textarea');
     if (input !== null) {
         var doc_name = 'test';
@@ -24,6 +25,7 @@ function opennamu_do_editor_preview() {
     }
 }
 function opennamu_do_editor_temp_save() {
+    do_sync_monaco_and_textarea();
     var input = document.querySelector('#opennamu_edit_textarea');
     if (input !== null) {
         localStorage.setItem("key", input.value);
@@ -31,15 +33,11 @@ function opennamu_do_editor_temp_save() {
 }
 function opennamu_do_editor_temp_save_load() {
     var data = localStorage.getItem("key");
-    console.log(data);
     if (data !== null) {
         var input = document.querySelector('#opennamu_edit_textarea');
         if (input !== null) {
             input.value = data;
         }
-        var input_2 = document.querySelector('#opennamu_monaco_editor');
-        if (input_2 !== null) {
-            window.editor.setValue(data);
-        }
+        do_textarea_to_manaco();
     }
 }

+ 9 - 6
views/main_css/js/route/editor_sub.ts

@@ -1,9 +1,14 @@
 declare function opennamu_do_url_encode(data : any) : string;
+declare function do_sync_monaco_and_textarea();
+declare function do_textarea_to_manaco();
+
 interface Window {
     editor? : any;
 }
 
 function opennamu_do_editor_preview() {
+    do_sync_monaco_and_textarea();
+
     const input = document.querySelector('#opennamu_edit_textarea') as HTMLInputElement | null;
     if(input !== null) {
         let doc_name : string = 'test';
@@ -32,6 +37,8 @@ function opennamu_do_editor_preview() {
 }
 
 function opennamu_do_editor_temp_save() {
+    do_sync_monaco_and_textarea();
+
     const input = document.querySelector('#opennamu_edit_textarea') as HTMLInputElement | null;
     if(input !== null) {
         localStorage.setItem("key", input.value);
@@ -40,16 +47,12 @@ function opennamu_do_editor_temp_save() {
 
 function opennamu_do_editor_temp_save_load() {
     const data = localStorage.getItem("key");
-    console.log(data);
     if(data !== null) {
         const input = document.querySelector('#opennamu_edit_textarea') as HTMLInputElement | null;
         if(input !== null) {
             input.value = data;
         }
-
-        const input_2 = document.querySelector('#opennamu_monaco_editor') as any;
-        if(input_2 !== null) {
-            window.editor.setValue(data);
-        }
+        
+        do_textarea_to_manaco();
     }
 }