sidebar.js 3.6 KB

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