load_topic.js 3.6 KB

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