2
0

load_topic.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. }