sidebar.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use strict";
  2. // func
  3. function ringo_do_xss_encode(data) {
  4. data = data.replace(/'/g, ''');
  5. data = data.replace(/"/g, '"');
  6. data = data.replace(/</g, '&lt;');
  7. data = data.replace(/</g, '&gt;');
  8. return data;
  9. }
  10. function ringo_do_url_encode(data) {
  11. return encodeURIComponent(data);
  12. }
  13. // event
  14. function ringo_do_side_button_1() {
  15. if(temp_save[0] === '') {
  16. fetch("/api/recent_change/10").then(function(res) {
  17. return res.json();
  18. }).then(function(text) {
  19. let data = '';
  20. for(let for_a = 0; for_a < text.length; for_a++) {
  21. if(text[for_a][6] === '') {
  22. data += '<a href="/w/' + ringo_do_url_encode(text[for_a][1]) + '">' + ringo_do_xss_encode(text[for_a][1]) + '</a><br>';
  23. data += text[for_a][2] + ' | ' + ringo_do_xss_encode(text[for_a][3]) + '<br>';
  24. }
  25. }
  26. document.getElementById('side_content').innerHTML = data;
  27. temp_save[0] = data;
  28. }).catch(function(error) {
  29. document.getElementById('side_content').innerHTML = 'Error';
  30. });
  31. } else {
  32. document.getElementById('side_content').innerHTML = temp_save[0];
  33. }
  34. }
  35. function ringo_do_side_button_2() {
  36. if(temp_save[1] === '') {
  37. fetch("/api/recent_discuss/10").then(function(res) {
  38. return res.json();
  39. }).then(function(text) {
  40. let data = '';
  41. for(let for_a = 0; for_a < text.length; for_a++) {
  42. data += '<a href="/thread/' + ringo_do_url_encode(text[for_a][3]) + '">' + ringo_do_xss_encode(text[for_a][1]) + '</a><br>';
  43. data += text[for_a][2] + ' | ' + text[for_a][5] +'<br>';
  44. }
  45. document.getElementById('side_content').innerHTML = data;
  46. temp_save[1] = data;
  47. }).catch(function(error) {
  48. document.getElementById('side_content').innerHTML = 'Error';
  49. });
  50. } else {
  51. document.getElementById('side_content').innerHTML = temp_save[1];
  52. }
  53. }
  54. function ringo_do_side_button_3() {
  55. if(temp_save[2] === '') {
  56. fetch("/api/v2/bbs/main").then(function(res) {
  57. return res.json();
  58. }).then(function(data) {
  59. let end_data = '';
  60. let text = data['data'];
  61. for(let for_a = 0; for_a < text.length; for_a++) {
  62. end_data += '<a href="/bbs/w/' + text[for_a].set_id + '/' + text[for_a].set_code + '">' + ringo_do_xss_encode(text[for_a].title) + '</a><br>';
  63. end_data += text[for_a].date + ' | ' + text[for_a].user_id +'<br>';
  64. }
  65. document.getElementById('side_content').innerHTML = end_data;
  66. temp_save[2] = end_data;
  67. });
  68. } else {
  69. document.getElementById('side_content').innerHTML = temp_save[2];
  70. }
  71. }
  72. // init
  73. let temp_save = ['', '', ''];
  74. window.addEventListener('DOMContentLoaded', function() {
  75. if(document.getElementById("side_button_1")) {
  76. document.getElementById("side_button_1").addEventListener("click", ringo_do_side_button_1);
  77. document.getElementById("side_button_2").addEventListener("click", ringo_do_side_button_2);
  78. document.getElementById("side_button_3").addEventListener("click", ringo_do_side_button_3);
  79. ringo_do_side_button_1();
  80. }
  81. });