sidebar.js 3.6 KB

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