topic.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. "use strict";
  2. function opennamu_do_remove_blind_thread() {
  3. const style = document.querySelector('#opennamu_remove_blind');
  4. if(style !== null) {
  5. if(style.innerHTML !== "") {
  6. style.innerHTML = '';
  7. } else {
  8. style.innerHTML = `
  9. .opennamu_comment_blind_js {
  10. display: none;
  11. }
  12. `;
  13. }
  14. }
  15. }
  16. function opennamu_thread_blind() {
  17. let do_true = 0;
  18. for(let for_a = 0; for_a < document.getElementsByClassName("opennamu_blind_button").length; for_a++) {
  19. let id = document.getElementsByClassName("opennamu_blind_button")[for_a].id;
  20. id = id.replace(/^opennamu_blind_/, '');
  21. id = id.split('_');
  22. let checked = document.getElementsByClassName("opennamu_blind_button")[for_a].checked;
  23. if(checked) {
  24. fetch("/thread/" + id[0] + '/comment/' + id[1] + '/blind', { method : 'GET' });
  25. do_true = 1;
  26. }
  27. }
  28. if(do_true === 1) {
  29. history.go(0);
  30. }
  31. }
  32. function opennamu_get_thread_ui(user_id, date, data, code, color = '', blind = '', add_style = '', topic_num = '') {
  33. let color_b, class_b;
  34. if(blind == 'O') {
  35. color_b = data == '' ? 'opennamu_comment_blind' : 'opennamu_comment_blind_admin';
  36. class_b = 'opennamu_comment_blind_js';
  37. } else {
  38. color_b = 'opennamu_comment_blind_not';
  39. class_b = '';
  40. }
  41. let admin_check_box = ''
  42. if(topic_num != '') {
  43. admin_check_box = '<input type="checkbox" class="opennamu_blind_button" id="opennamu_blind_' + topic_num + '_' + code + '">';
  44. }
  45. return `
  46. <span class="` + class_b + `">
  47. <table class="opennamu_comment" style="` + add_style + `">
  48. <tr>
  49. <td class="opennamu_comment_color_` + color + `">
  50. ` + admin_check_box + `
  51. <a href="#thread_shortcut" id="` + code + `">#` + code + `</a>
  52. ` + user_id + `
  53. <span style="float: right;">` + date + `</span>
  54. </td>
  55. </tr>
  56. <tr>
  57. <td class="` + color_b + ` opennamu_comment_data_main" id="thread_` + code + `">
  58. ` + data + `
  59. <div id="opennamu_topic_req_` + code + `"></div>
  60. </td>
  61. </tr>
  62. </table>
  63. <hr class="main_hr">
  64. </span>
  65. `;
  66. }
  67. function opennamu_get_thread(topic_num = "", do_type = "") {
  68. let url, to_obj, color;
  69. if(do_type === "top") {
  70. url = "/api/thread/" + topic_num + "/top";
  71. to_obj = 'opennamu_top_thread';
  72. color = 'red';
  73. } else {
  74. url = "/api/thread/" + topic_num;
  75. to_obj = 'opennamu_main_thread';
  76. color = 'default';
  77. }
  78. fetch(url).then(function(res) {
  79. return res.json();
  80. }).then(function(data) {
  81. fetch("/api/lang/tool").then(function(res) {
  82. return res.json();
  83. }).then(function(tool_lang) {
  84. let end_data = '';
  85. let end_render = [];
  86. data = data["data"];
  87. tool_lang = tool_lang["data"];
  88. let first = data[0]["ip"];
  89. for(let for_a = 0; for_a < data.length; for_a++) {
  90. if(color !== 'red') {
  91. if(data[for_a]["blind"] === '1') {
  92. color = 'blue';
  93. } else if(first === data[for_a]["ip"]) {
  94. color = 'green';
  95. } else {
  96. color = 'default';
  97. }
  98. }
  99. let date = '<a href="/thread/' + topic_num + '/comment/' + data[for_a]["id"] + '/tool">(' + tool_lang + ')</a> ' + data[for_a]["date"];
  100. end_data += opennamu_get_thread_ui(
  101. data[for_a]["ip_render"],
  102. date,
  103. '<div id="opennamu_' + color + '_thread_render_' + data[for_a]["id"] + '"></div>',
  104. data[for_a]["id"],
  105. color,
  106. data[for_a]["blind"],
  107. '',
  108. topic_num
  109. )
  110. end_render.push([
  111. data[for_a]["data"] !== "" ? data[for_a]["data"] : "[br]",
  112. data[for_a]["id"]
  113. ]);
  114. }
  115. document.getElementById(to_obj).innerHTML = end_data;
  116. for(let for_a = 0; for_a < end_render.length; for_a++) {
  117. opennamu_do_render(
  118. 'opennamu_' + color + '_thread_render_' + end_render[for_a][1],
  119. "thread_" + topic_num + "_" + color + "_" + end_render[for_a][1],
  120. end_render[for_a][0],
  121. 'thread'
  122. );
  123. }
  124. });
  125. });
  126. }