load_topic.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. function topic_list_load(topic_num, s_num, where) {
  2. var o_data = document.getElementById(where);
  3. var url = "/api/thread/" + String(topic_num) + "?render=1&num=" + String(s_num);
  4. var n_data = "";
  5. var xhr = new XMLHttpRequest();
  6. xhr.open("GET", url, true);
  7. xhr.send(null);
  8. xhr.onreadystatechange = function() {
  9. if(this.readyState === 4 && this.status === 200) {
  10. var t_data = JSON.parse(this.responseText);
  11. var t_plus_data = '';
  12. for(key in t_data) {
  13. n_data += t_data[key]['data'];
  14. t_plus_data += t_data[key]['plus_data'];
  15. }
  16. o_data.innerHTML = n_data;
  17. eval(t_plus_data);
  18. }
  19. }
  20. }
  21. function topic_plus_load(topic_num, num) {
  22. var test = setInterval(function() {
  23. var url = "/api/thread/" + String(topic_num) + "?num=" + num + "&render=1";
  24. var p_data = document.getElementById("plus_topic");
  25. var n_data = '';
  26. var n_num = 1;
  27. var xhr = new XMLHttpRequest();
  28. xhr.open("GET", url, true);
  29. xhr.send(null);
  30. xhr.onreadystatechange = function() {
  31. if(this.readyState === 4 && this.status === 200 && this.responseText !== '{}\n') {
  32. var t_data = JSON.parse(this.responseText);
  33. var t_plus_data = '';
  34. for(key in t_data) {
  35. n_data += t_data[key]['data'];
  36. n_num = key;
  37. t_plus_data += t_data[key]['plus_data'];
  38. }
  39. p_data.innerHTML += n_data;
  40. eval(t_plus_data);
  41. // https://programmingsummaries.tistory.com/379
  42. var notification = new Notification("openNAMU", { body: '#' + n_num });
  43. setTimeout(function () {
  44. notification.close();
  45. }, 5000);
  46. topic_plus_load(topic_num, String(Number(num) + 1));
  47. clearInterval(test);
  48. }
  49. }
  50. }, 5000);
  51. }
  52. function topic_main_load(topic_num, s_num) {
  53. var o_data = document.getElementById('main_topic');
  54. if(s_num) {
  55. var url = "/api/thread/" + String(topic_num) + "?render=1&num=" + s_num;
  56. } else {
  57. var url = "/api/thread/" + String(topic_num) + "?render=1";
  58. }
  59. var n_data = "";
  60. var num = 1;
  61. var xhr = new XMLHttpRequest();
  62. xhr.open("GET", url, true);
  63. xhr.send(null);
  64. xhr.onreadystatechange = function() {
  65. if(this.readyState === 4 && this.status === 200) {
  66. var t_data = JSON.parse(this.responseText);
  67. var t_plus_data = '';
  68. for(var key in t_data) {
  69. n_data += t_data[key]['data'];
  70. num = key;
  71. t_plus_data += t_data[key]['plus_data'];
  72. }
  73. o_data.innerHTML = n_data;
  74. eval(t_plus_data);
  75. if(window.location.search === "?where=bottom") {
  76. document.getElementById(num).focus();
  77. }
  78. if(!s_num) {
  79. topic_plus_load(topic_num, String(Number(num) + 1));
  80. }
  81. }
  82. }
  83. }
  84. function topic_top_load(topic_num) {
  85. var o_data = document.getElementById('top_topic');
  86. var url = "/api/thread/" + String(topic_num) + "?top=1&render=1";
  87. var n_data = "";
  88. var num = 1;
  89. var xhr = new XMLHttpRequest();
  90. xhr.open("GET", url, true);
  91. xhr.send(null);
  92. xhr.onreadystatechange = function() {
  93. if(this.readyState === 4 && this.status === 200) {
  94. var t_data = JSON.parse(this.responseText);
  95. var t_plus_data = '';
  96. for(var key in t_data) {
  97. n_data += t_data[key]['data'];
  98. num = key;
  99. t_plus_data += t_data[key]['plus_data'];
  100. }
  101. o_data.innerHTML = n_data;
  102. eval(t_plus_data);
  103. topic_main_load(topic_num, null);
  104. }
  105. }
  106. }