load_topic.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 options = {
  43. body: '#' + n_num
  44. }
  45. var notification = new Notification("openNAMU", options);
  46. setTimeout(function () {
  47. notification.close();
  48. }, 5000);
  49. topic_plus_load(topic_num, String(Number(num) + 1));
  50. clearInterval(test);
  51. }
  52. }
  53. }, 2000);
  54. }
  55. function topic_main_load(topic_num, s_num) {
  56. var o_data = document.getElementById('main_topic');
  57. if(s_num) {
  58. var url = "/api/thread/" + String(topic_num) + "?render=1&num=" + s_num;
  59. } else {
  60. var url = "/api/thread/" + String(topic_num) + "?render=1";
  61. }
  62. var n_data = "";
  63. var num = 1;
  64. var xhr = new XMLHttpRequest();
  65. xhr.open("GET", url, true);
  66. xhr.send(null);
  67. xhr.onreadystatechange = function() {
  68. if(xhr.readyState === 4 && xhr.status === 200) {
  69. var t_data = JSON.parse(xhr.responseText);
  70. var t_plus_data = '';
  71. for(var key in t_data) {
  72. n_data += t_data[key]['data'];
  73. num = key;
  74. t_plus_data += t_data[key]['plus_data'];
  75. }
  76. o_data.innerHTML = n_data;
  77. eval(t_plus_data);
  78. if(window.location.search === "?where=bottom") {
  79. document.getElementById(num).focus();
  80. }
  81. if(!s_num) {
  82. topic_plus_load(topic_num, String(Number(num) + 1));
  83. }
  84. }
  85. }
  86. }
  87. function topic_top_load(topic_num) {
  88. var o_data = document.getElementById('top_topic');
  89. var url = "/api/thread/" + String(topic_num) + "?top=1&render=1";
  90. var n_data = "";
  91. var num = 1;
  92. var xhr = new XMLHttpRequest();
  93. xhr.open("GET", url, true);
  94. xhr.send(null);
  95. xhr.onreadystatechange = function() {
  96. if(this.readyState === 4 && this.status === 200) {
  97. var t_data = JSON.parse(this.responseText);
  98. var t_plus_data = '';
  99. for(var key in t_data) {
  100. n_data += t_data[key]['data'];
  101. num = key;
  102. t_plus_data += t_data[key]['plus_data'];
  103. }
  104. o_data.innerHTML = n_data;
  105. eval(t_plus_data);
  106. topic_main_load(topic_num, null);
  107. }
  108. }
  109. }