Ver código fonte

나무위키처럼 바로 갱신되게

Surplus_Up (2DU) 6 anos atrás
pai
commit
de6e9d751d
2 arquivos alterados com 32 adições e 17 exclusões
  1. 8 0
      route/api_topic_sub.py
  2. 24 17
      views/main_css/js/topic_plus_load.js

+ 8 - 0
route/api_topic_sub.py

@@ -36,6 +36,14 @@ def api_topic_sub_2(conn, name, sub, time):
             if flask.request.args.get('render', None):
                 if i[0] == '1':
                     s_user = i[3]
+                else:
+                    if flask.request.args.get('num', None):
+                        curs.execute("select ip from topic where title = ? and sub = ? order by id + 0 asc limit 1", [name, sub])
+                        g_data = curs.fetchall()
+                        if g_data:
+                            s_user = g_data[0][0]
+                        else:
+                            s_user = ''
                     
                 if flask.request.args.get('top', None):
                     t_color = 'toron_color_red'

+ 24 - 17
views/main_css/js/topic_plus_load.js

@@ -1,30 +1,37 @@
 function topic_plus_load(name, sub, num) {
     var test = setInterval(function() {
-        var url = "/api/topic/" + name + "/sub/" + sub + "?num=" + num;
-        var doc_data = document.getElementById("plus_topic");
+        var url = "/api/topic/" + name + "/sub/" + sub + "?num=" + num + "&render=1";
+        var p_data = document.getElementById("plus_topic");
+        var n_data = '';
+        var n_num = 1;
 
         var xhr = new XMLHttpRequest();
         xhr.open("GET", url, true);
         xhr.send(null);
 
         xhr.onreadystatechange = function() {
-            if(this.readyState === 4 && this.status === 200) {
-                if(this.responseText) {
-                    doc_data.innerHTML += '<hr class="main_hr">(New)<hr class="main_hr">';
-
-                    // https://programmingsummaries.tistory.com/379
-                    var options = {
-                        body: 'New topic'
-                    }
-                   
-                    var notification = new Notification("openNAMU", options);
-                    
-                    setTimeout(function () {
-                        notification.close();
-                    }, 5000);
+            if(this.readyState === 4 && this.status === 200 && this.responseText && this.responseText !== {}) {                
+                t_data = JSON.parse(this.responseText);
+                for(key in t_data) {
+                    n_data += t_data[key]['data'];
+                    n_num = key;
+                }
+                
+                p_data.innerHTML += n_data;
 
-                    clearInterval(test);
+                // https://programmingsummaries.tistory.com/379
+                var options = {
+                    body: 'New ' + n_num + ' topic'
                 }
+               
+                var notification = new Notification("openNAMU", options);
+                
+                setTimeout(function () {
+                    notification.close();
+                }, 5000);
+
+                topic_plus_load(name, sub, String(Number(num) + 1));
+                clearInterval(test);
             }
         }
     }, 2000);