load_something.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. function load_user_info(name) {
  2. var url = "/api/user_info/" + encodeURI(name) + "?render=1";
  3. var xhr = new XMLHttpRequest();
  4. xhr.open("GET", url, true);
  5. xhr.send(null);
  6. xhr.onreadystatechange = function() {
  7. if(this.readyState === 4 && this.status === 200) {
  8. document.getElementById('get_user_info').innerHTML += JSON.parse(this.responseText)['data'];
  9. }
  10. }
  11. }
  12. function load_ver() {
  13. var url = "/api/version";
  14. var xhr = new XMLHttpRequest();
  15. xhr.open("GET", url, true);
  16. xhr.send(null);
  17. xhr.onreadystatechange = function() {
  18. if(this.readyState === 4 && this.status === 200) {
  19. document.getElementById('ver_send').innerHTML += JSON.parse(this.responseText)['lastest_version'];
  20. document.getElementById('ver_send').style.display = "list-item";
  21. }
  22. }
  23. }
  24. function do_skin_ver_check() {
  25. var url = "/api/skin_info?all=true";
  26. var xhr = new XMLHttpRequest();
  27. xhr.open("GET", url, true);
  28. xhr.send(null);
  29. xhr.onreadystatechange = function() {
  30. if(this.readyState === 4 && this.status === 200) {
  31. var json_data = JSON.parse(this.responseText);
  32. var all_need_update = [];
  33. for(var key in json_data) {
  34. if(json_data[key]['lastest_version']) {
  35. var new_skin_ver = json_data[key]['lastest_version']['skin_ver'];
  36. var old_skin_ver = json_data[key]['skin_ver'];
  37. var skin_name = json_data[key]['name'];
  38. if(new_skin_ver !== old_skin_ver) {
  39. all_need_update.push(skin_name);
  40. }
  41. }
  42. }
  43. if(all_need_update.length !== 0) {
  44. document.getElementById('need_skin_update').innerHTML += ' (' + (all_need_update.join(', ')) + ')';
  45. }
  46. }
  47. }
  48. }
  49. function do_twofa_check(init = 0) {
  50. let twofa_option = document.getElementById('twofa_check_input');
  51. let twofa_option_num = twofa_option.options.selectedIndex;
  52. let twofa_select_data = twofa_option.options[twofa_option_num].value;
  53. if(twofa_select_data === 'on') {
  54. document.getElementById('fa_plus_content').style.display = "block";
  55. } else {
  56. document.getElementById('fa_plus_content').style.display = "none";
  57. }
  58. }
  59. function send_render(i = 0) {
  60. var get_class = document.getElementsByClassName('send_content')[i];
  61. if(get_class) {
  62. send_render(i + 1);
  63. var data = get_class.innerHTML;
  64. if(data === '<br>') {
  65. document.getElementsByClassName('send_content')[i].innerHTML = '<br>';
  66. } else {
  67. data = data.replace(/javascript:/i, '');
  68. data = data.replace(/&lt;a&gt;((?:(?!&lt;\/a&gt;).)+)&lt;\/a&gt;/g, function(x, x_1) {
  69. return '<a href="/w/' + encodeURIComponent(x_1) + '">' + x_1 + '</a>';
  70. });
  71. document.getElementsByClassName('send_content')[i].innerHTML = data;
  72. }
  73. }
  74. }
  75. function simple_render(name_ele) {
  76. var skin_set_data = document.getElementById(name_ele).innerHTML;
  77. // 목차 구현
  78. var toc_all_data = '<div id="toc"><span id="toc_title">TOC</span><br>';
  79. var split_toc;
  80. var toc_data;
  81. i = 1;
  82. while(1) {
  83. toc_data = skin_set_data.match(/<h[1-6]>([^<>]+)<\/h[1-6]>/);
  84. if(toc_data) {
  85. split_toc = toc_data[1].match(/^([^ ]+)(.+)/);
  86. toc_all_data += '' +
  87. '<br>' +
  88. '<span style="margin-left: ' + String(((toc_data[1].match(/\./g) || []).length - 1) * 10) + 'px;">' +
  89. '<a href="#toc_' + String(i) + '">' + split_toc[1] + '</a>' + split_toc[2] +
  90. '</span>' +
  91. '';
  92. skin_set_data = skin_set_data.replace(
  93. /<(h[1-6])>([^<>]+)<\/h[1-6]>/,
  94. '<$1 id="toc_' + String(i) + '"><a href="#toc">' + split_toc[1] + '</a>' + split_toc[2] + '</$1>'
  95. );
  96. i += 1;
  97. } else {
  98. break;
  99. }
  100. }
  101. skin_set_data = toc_all_data + '</div>' + skin_set_data;
  102. // 각주 구현
  103. var note_list = {};
  104. var plus_note;
  105. i = 1;
  106. while(1) {
  107. toc_data = skin_set_data.match(/<sup>([^<>]+)<\/sup>/);
  108. if(toc_data) {
  109. if(!note_list[toc_data[1]]) {
  110. note_list[toc_data[1]] = [String(i), 0];
  111. } else {
  112. note_list[toc_data[1]][1] += 1;
  113. }
  114. if(note_list[toc_data[1]][1] != 0) {
  115. plus_note = '_' + String(note_list[toc_data[1]][1]);
  116. } else {
  117. plus_note = '';
  118. }
  119. skin_set_data = skin_set_data.replace(
  120. /<sup>([^<>]+)<\/sup>/,
  121. '<sup><a id="note_' + note_list[toc_data[1]][0] + plus_note + '" href="#note_' + note_list[toc_data[1]][0] + '_end">$1</a></sup>'
  122. );
  123. i += 1;
  124. } else {
  125. break;
  126. }
  127. }
  128. document.getElementById(name_ele).innerHTML = skin_set_data;
  129. }
  130. function ie_end_support() {
  131. if(document.currentScript === undefined) {
  132. window.location = 'microsoft-edge:' + window.location;
  133. setTimeout(function() {
  134. window.location = 'https://go.microsoft.com/fwlink/?linkid=2135547';
  135. }, 1);
  136. }
  137. }
  138. ie_end_support();