load_topic.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. function new_topic_load(topic_num, type_do = 'top', some = '', where = 'top_topic') {
  2. if(type_do === 'top') {
  3. var url = "/api/thread/" + topic_num + "/top";
  4. } else if(type_do === 'main') {
  5. var url = "/api/thread/" + topic_num;
  6. } else {
  7. var url = "/api/thread/" + topic_num + some;
  8. }
  9. var xhr = new XMLHttpRequest();
  10. xhr.open("GET", url, true);
  11. xhr.send(null);
  12. xhr.onreadystatechange = function() {
  13. if(this.readyState === 4 && this.status === 200) {
  14. var data_t = JSON.parse(this.responseText);
  15. var start = 0;
  16. var key_v = '/normal/1';
  17. for(var key in data_t) {
  18. var data_a = '';
  19. if(start === 0) {
  20. var admin = data_t['data_main']['admin'];
  21. var ip_first = data_t['data_main']['ip_first'];
  22. start = 1;
  23. }
  24. if(key === 'data_main') {
  25. continue;
  26. }
  27. key_v = '/normal/' + String(Number(key) + 1);
  28. var color_b = '';
  29. var color_t = '';
  30. var ip = data_t[key]['ip_pas'];
  31. var ip_o = data_t[key]['ip'];
  32. var blind = data_t[key]['blind'];
  33. var data_i_pas = data_t[key]['data_pas'][0];
  34. if(data_i_pas === '') {
  35. data_i_pas = '<br>';
  36. } else {
  37. data_i_pas = data_i_pas.replace(
  38. /&lt;topic_a&gt;((?:(?!&lt;\/topic_a&gt;).)+)&lt;\/topic_a&gt;/g,
  39. '<a href="$1">$1</a>'
  40. );
  41. data_i_pas = data_i_pas.replace(
  42. /&lt;topic_call&gt;@((?:(?!&lt;\/topic_call&gt;).)+)&lt;\/topic_call&gt;/g,
  43. '<a href="/w/user:$1">@$1</a>',
  44. );
  45. }
  46. if(blind === 'O') {
  47. color_b = 'toron_color_not';
  48. } else {
  49. color_b = 'toron_color';
  50. }
  51. if(blind === 'O') {
  52. ip += ' <a href="/admin_log?search=blind%20(code%20' + topic_num + '#' + key + '">(B)</a>';
  53. if(admin === '1') {
  54. ip += ' <a href="/thread/' + topic_num + '/raw/' + key + '">(R)</a>';
  55. }
  56. }
  57. if(admin === '1' || blind !== 'O') {
  58. ip += ' <a href="/thread/' + topic_num + '/admin/' + key + '">(T)</a>';
  59. }
  60. if(type_do === 'top') {
  61. color_t = 'toron_color_red';
  62. } else if(blind === '1') {
  63. color_t = 'toron_color_blue';
  64. } else if(ip_o === ip_first) {
  65. color_t = 'toron_color_green';
  66. } else {
  67. color_t = 'toron_color_normal';
  68. }
  69. data_a += '' +
  70. '<table id="toron">' +
  71. '<tr>' +
  72. '<td id="' + color_t + '">' +
  73. '<a href="javascript:void(0);" id="' + key + '">#' + key + '</a> ' +
  74. ip +
  75. '<span style="float: right;">' + data_t[key]['date'] + '</span>' +
  76. '</td>' +
  77. '</tr>' +
  78. '<tr>' +
  79. '<td id="' + color_b + '">' +
  80. '<div id="topic_scroll">' + data_i_pas + '</div>' +
  81. '</td>' +
  82. '</tr>' +
  83. '</table>' +
  84. '<hr class="main_hr">' +
  85. ''
  86. document.getElementById(where).innerHTML += data_a;
  87. eval(data_t[key]['data_pas'][1]);
  88. }
  89. opennamu_do_ip_parser();
  90. if(type_do === 'top') {
  91. new_topic_load(topic_num, 'main', '', 'main_topic');
  92. } else if(type_do === 'main') {
  93. data_url_v = window.location.href.split('#');
  94. if(data_url_v.length !== 0) {
  95. if(document.getElementById(data_url_v[1])) {
  96. document.getElementById(data_url_v[1]).focus();
  97. }
  98. }
  99. new_topic_load(topic_num, 're', key_v, where);
  100. } else if(type_do === 're') {
  101. setTimeout(function() {
  102. if(start === 0) {
  103. new_topic_load(topic_num, 're', some, where);
  104. } else {
  105. new_topic_load(topic_num, 're', key_v, where);
  106. }
  107. }, 2000);
  108. }
  109. }
  110. }
  111. }