2
0

topic_plus_load.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. function topic_plus_load(topic_num, num) {
  2. var test = setInterval(function() {
  3. var url = "/api/thread/" + String(topic_num) + "?num=" + num + "&render=1";
  4. var p_data = document.getElementById("plus_topic");
  5. var n_data = '';
  6. var n_num = 1;
  7. var url_2 = "/api/markup";
  8. var xhr = new XMLHttpRequest();
  9. xhr.open("GET", url, true);
  10. xhr.send(null);
  11. var xhr_2 = new XMLHttpRequest();
  12. xhr_2.open("GET", url_2, true);
  13. xhr_2.send(null);
  14. xhr.onreadystatechange = function() {
  15. if(this.readyState === 4 && this.status === 200 && this.responseText !== '{}\n') {
  16. var t_data = JSON.parse(this.responseText);
  17. var t_plus_data = '';
  18. for(key in t_data) {
  19. n_data += t_data[key]['data'];
  20. n_num = key;
  21. t_plus_data += t_data[key]['plus_data'].replace(/<script>/g, '').replace(/<\/script>/g, '');
  22. }
  23. p_data.innerHTML += n_data;
  24. eval(t_plus_data);
  25. // https://programmingsummaries.tistory.com/379
  26. var options = {
  27. body: '#' + n_num
  28. }
  29. var notification = new Notification("openNAMU", options);
  30. setTimeout(function () {
  31. notification.close();
  32. }, 5000);
  33. topic_plus_load(topic_num, String(Number(num) + 1));
  34. clearInterval(test);
  35. }
  36. }
  37. }, 2000);
  38. }