load_topic.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. function topic_list_load(topic_num, s_num, where) {
  2. var url = "/api/thread/" + String(topic_num) + "?render=1&num=" + String(s_num);
  3. var n_data = "";
  4. var xhr = new XMLHttpRequest();
  5. xhr.open("GET", url, true);
  6. xhr.send(null);
  7. xhr.onreadystatechange = function() {
  8. if(this.readyState === 4 && this.status === 200) {
  9. var t_data = JSON.parse(this.responseText);
  10. var t_plus_data = '';
  11. for(key in t_data) {
  12. n_data += t_data[key]['data'];
  13. t_plus_data += t_data[key]['plus_data'];
  14. }
  15. document.getElementById(where).innerHTML = n_data;
  16. eval(t_plus_data);
  17. }
  18. }
  19. }
  20. function topic_plus_load(topic_num, num) {
  21. var test = setInterval(function() {
  22. var url = "/api/thread/" + String(topic_num) + "?num=" + num + "&render=1";
  23. var n_data = '';
  24. var n_num = 1;
  25. var xhr = new XMLHttpRequest();
  26. xhr.open("GET", url, true);
  27. xhr.send(null);
  28. xhr.onreadystatechange = function() {
  29. if(this.readyState === 4 && this.status === 200 && this.responseText !== '{}\n') {
  30. var t_data = JSON.parse(this.responseText);
  31. var t_plus_data = '';
  32. for(key in t_data) {
  33. n_data += t_data[key]['data'];
  34. n_num = key;
  35. t_plus_data += t_data[key]['plus_data'];
  36. }
  37. document.getElementById("plus_topic").innerHTML += n_data;
  38. eval(t_plus_data);
  39. topic_plus_load(topic_num, String(Number(num) + 1));
  40. clearInterval(test);
  41. }
  42. }
  43. }, 5000);
  44. }
  45. function topic_main_load(topic_num, s_num) {
  46. if(s_num) {
  47. var url = "/api/thread/" + String(topic_num) + "?render=1&num=" + s_num;
  48. } else {
  49. var url = "/api/thread/" + String(topic_num) + "?render=1";
  50. }
  51. var n_data = "";
  52. var num = 1;
  53. var xhr = new XMLHttpRequest();
  54. xhr.open("GET", url, true);
  55. xhr.send(null);
  56. xhr.onreadystatechange = function() {
  57. if(this.readyState === 4 && this.status === 200) {
  58. var t_data = JSON.parse(this.responseText);
  59. var t_plus_data = '';
  60. for(var key in t_data) {
  61. n_data += t_data[key]['data'];
  62. num = key;
  63. t_plus_data += t_data[key]['plus_data'];
  64. }
  65. document.getElementById('main_topic').innerHTML = n_data;
  66. eval(t_plus_data);
  67. if(window.location.hash) {
  68. document.getElementById(window.location.hash.replace(/^#/, '')).focus();
  69. }
  70. if(!s_num) {
  71. topic_plus_load(topic_num, String(Number(num) + 1));
  72. }
  73. }
  74. }
  75. }
  76. function topic_top_load(topic_num) {
  77. var url = "/api/thread/" + String(topic_num) + "?top=1&render=1";
  78. var n_data = "";
  79. var num = 1;
  80. var xhr = new XMLHttpRequest();
  81. xhr.open("GET", url, true);
  82. xhr.send(null);
  83. xhr.onreadystatechange = function() {
  84. if(this.readyState === 4 && this.status === 200) {
  85. var t_data = JSON.parse(this.responseText);
  86. var t_plus_data = '';
  87. for(var key in t_data) {
  88. n_data += t_data[key]['data'];
  89. num = key;
  90. t_plus_data += t_data[key]['plus_data'];
  91. }
  92. document.getElementById('top_topic').innerHTML = n_data;
  93. eval(t_plus_data);
  94. topic_main_load(topic_num, null);
  95. }
  96. }
  97. }
  98. function new_topic_load(topic_num, con = 1, type_do = 0, some = '', where = 'top_topic') {
  99. if(type_do === 0) {
  100. var url = "/api/thread/" + topic_num + "?top=1";
  101. } else {
  102. var url = "/api/thread/" + topic_num + some;
  103. }
  104. var xhr = new XMLHttpRequest();
  105. xhr.open("GET", url, true);
  106. xhr.send(null);
  107. xhr.onreadystatechange = function() {
  108. if(this.readyState === 4 && this.status === 200) {
  109. var data_t = JSON.parse(this.responseText);
  110. var data_a = '';
  111. var start = 0;
  112. for(var key in data_t) {
  113. if(start === 0) {
  114. var admin = data_t['data_main']['admin'];
  115. var ip_first = data_t['data_main']['ip_first'];
  116. start = 1;
  117. }
  118. if(key === 'data_main') {
  119. continue;
  120. }
  121. var color_b = '';
  122. var color_t = '';
  123. var ip = data_t[key]['ip_pas'];
  124. var ip_o = data_t[key]['ip'];
  125. var blind = data_t[key]['blind'];
  126. var data_i = data_t[key]['data'];
  127. if(data_i === '') {
  128. data_i = '<br>';
  129. }
  130. if(blind === 'O') {
  131. color_b = 'toron_color_not';
  132. } else {
  133. color_b = 'toron_color';
  134. }
  135. if(blind === 'O') {
  136. ip += ' <a href="/admin_log?search=blind%20(code%20' + topic_num + '#' + i[0] + '">(B)</a>';
  137. if(admin === '1') {
  138. ip += ' <a href="/thread/' + topic_num + '/raw/' + key + '">(R)</a>';
  139. }
  140. }
  141. if(admin === '1' || blind !== 'O') {
  142. ip += ' <a href="/thread/' + topic_num + '/admin/' + key + '">(T)</a>';
  143. }
  144. if(type_do === 0) {
  145. color_t = 'toron_color_red';
  146. } else if(blind === '1') {
  147. color_t = 'toron_color_blue';
  148. } else if(ip_o === ip_first) {
  149. color_t = 'toron_color_green';
  150. } else {
  151. color_t = 'toron_color';
  152. }
  153. data_a += '' +
  154. '<table id="toron">' +
  155. '<tr>' +
  156. '<td id="' + color_t + '">' +
  157. '<a href="javascript:void(0);" id="' + key + '">#' + key + '</a> ' +
  158. ip +
  159. '<span style="float: right;">' + data_t[key]['date'] + '</span>' +
  160. '</td>' +
  161. '</tr>' +
  162. '<tr>' +
  163. '<td id="' + color_b + '">' +
  164. '<div id="topic_scroll">' + data_t[key]['data'] + '</div>' +
  165. '</td>' +
  166. '</tr>' +
  167. '</table>' +
  168. '<hr class="main_hr">' +
  169. ''
  170. }
  171. document.getElementById(where).innerHTML += data_a;
  172. if(con === 1) {
  173. new_topic_load(topic_num, 0, type_do + 1, '', where);
  174. }
  175. }
  176. }
  177. }