sidebar.js 3.4 KB

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