load_namumark.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. function get_link_state(data, i = 0) {
  2. var get_class = document.getElementsByClassName(data + 'link_finder')[i];
  3. if(get_class) {
  4. var xhr = new XMLHttpRequest();
  5. xhr.open("GET", get_class.href.replace('/w/', '/api/w/').replace(/#([^#]*)/, '') + "?exist=1");
  6. xhr.send();
  7. xhr.onreadystatechange = function() {
  8. if(this.readyState === 4 && this.status === 200) {
  9. if(JSON.parse(this.responseText)['exist'] !== '1') {
  10. document.getElementsByClassName(data + 'link_finder')[i].id = "not_thing";
  11. } else {
  12. document.getElementsByClassName(data + 'link_finder')[i].id = "";
  13. }
  14. }
  15. }
  16. get_link_state(data, i + 1);
  17. }
  18. }
  19. function load_image_link(data) {
  20. data.innerHTML = '' +
  21. '<img style="' + data.getAttribute('under_style') + '" ' +
  22. 'alt="' + data.getAttribute('under_alt') + '" ' +
  23. 'src="' + data.getAttribute('under_src') + '">' +
  24. '';
  25. }
  26. function get_file_state(data, i = 0) {
  27. var get_class = document.getElementsByClassName(data + 'file_finder')[i];
  28. if(get_class) {
  29. if(get_class.getAttribute('under_href') === 'out_link') {
  30. if(
  31. document.cookie.match(main_css_regex_data('main_css_image_set')) &&
  32. document.cookie.match(main_css_regex_data('main_css_image_set'))[1] === '1'
  33. ) {
  34. document.getElementsByClassName(data + 'file_finder')[i].innerHTML = '' +
  35. '<a href="' + get_class.getAttribute('under_src') + '" ' +
  36. 'title="' + get_class.getAttribute('under_src') + '">' +
  37. '(External image link)' +
  38. '</a>' +
  39. '';
  40. } else if(
  41. document.cookie.match(main_css_regex_data('main_css_image_set')) &&
  42. document.cookie.match(main_css_regex_data('main_css_image_set'))[1] === '2'
  43. ) {
  44. document.getElementsByClassName(data + 'file_finder')[i].innerHTML = '' +
  45. '<a href="javascript:void(0);" ' +
  46. 'onclick="load_image_link(this); this.onclick = \'\';" ' +
  47. 'under_style="' + get_class.getAttribute('under_style') + '" ' +
  48. 'under_alt="' + get_class.getAttribute('under_alt') + '" ' +
  49. 'under_src="' + get_class.getAttribute('under_src') + '" ' +
  50. 'title="' + get_class.getAttribute('under_src') + '">' +
  51. '(External image load)' +
  52. '</a>' +
  53. '';
  54. } else {
  55. document.getElementsByClassName(data + 'file_finder')[i].innerHTML = '' +
  56. '<img style="' + get_class.getAttribute('under_style') + '" ' +
  57. 'alt="' + get_class.getAttribute('under_alt') + '" ' +
  58. 'src="' + get_class.getAttribute('under_src') + '">' +
  59. '';
  60. }
  61. } else {
  62. var xhr = new XMLHttpRequest();
  63. xhr.open("GET", get_class.getAttribute('under_src').replace('/image/', '/api/image/'));
  64. xhr.send();
  65. xhr.onreadystatechange = function() {
  66. if(this.readyState === 4 && this.status === 200) {
  67. if(JSON.parse(this.responseText)['exist'] !== '1') {
  68. document.getElementsByClassName(data + 'file_finder')[i].innerHTML = '' +
  69. '<a href="' + get_class.getAttribute('under_href') + '" ' +
  70. 'id="not_thing">' +
  71. '(' + get_class.getAttribute('under_alt') + ')' +
  72. '</a>' +
  73. '';
  74. } else {
  75. if(
  76. document.cookie.match(main_css_regex_data('main_css_image_set')) &&
  77. document.cookie.match(main_css_regex_data('main_css_image_set'))[1] === '1'
  78. ) {
  79. document.getElementsByClassName(data + 'file_finder')[i].innerHTML = '' +
  80. '<a href="' + get_class.getAttribute('under_src') + '">' +
  81. '(' + get_class.getAttribute('under_alt') + ')' +
  82. '</a>' +
  83. '';
  84. } else if(
  85. document.cookie.match(main_css_regex_data('main_css_image_set')) &&
  86. document.cookie.match(main_css_regex_data('main_css_image_set'))[1] === '2'
  87. ) {
  88. document.getElementsByClassName(data + 'file_finder')[i].innerHTML = '' +
  89. '<a href="javascript:void(0);" ' +
  90. 'onclick="load_image_link(this); this.onclick = \'\';" ' +
  91. 'under_style="' + get_class.getAttribute('under_style') + '" ' +
  92. 'under_alt="' + get_class.getAttribute('under_alt') + '" ' +
  93. 'under_src="' + get_class.getAttribute('under_src') + '">' +
  94. '(' + get_class.getAttribute('under_alt') + ' load)' +
  95. '</a>' +
  96. '';
  97. } else {
  98. document.getElementsByClassName(data + 'file_finder')[i].innerHTML = '' +
  99. '<img style="' + get_class.getAttribute('under_style') + '" ' +
  100. 'alt="' + get_class.getAttribute('under_alt') + '" ' +
  101. 'src="' + get_class.getAttribute('under_src') + '">' +
  102. '';
  103. }
  104. }
  105. }
  106. }
  107. }
  108. get_file_state(data, i + 1);
  109. }
  110. }
  111. function load_include(title, name, p_data) {
  112. var change = '';
  113. for(key in p_data) {
  114. change += '@' + p_data[key][0].replace('&', '<amp>') + '@,' + p_data[key][1].replace(',', '<comma>').replace('&', '<amp>') + ','
  115. }
  116. var url = "/api/w/" + encodeURI(title) + "?include=" + name + "&change=" + change;
  117. var xhr = new XMLHttpRequest();
  118. xhr.open("GET", url);
  119. xhr.send();
  120. console.log(url);
  121. xhr.onreadystatechange = function() {
  122. if(this.readyState === 4 && this.status === 200) {
  123. if(this.responseText === "{}\n") {
  124. document.getElementById(name).innerHTML = "";
  125. document.getElementsByClassName(name)[0].id = "not_thing";
  126. } else {
  127. var o_p_data = JSON.parse(this.responseText);
  128. document.getElementById(name).innerHTML = o_p_data['data'];
  129. eval(o_p_data['js_data']);
  130. }
  131. }
  132. }
  133. }
  134. function page_count() {
  135. var url = "/api/title_index";
  136. var xhr = new XMLHttpRequest();
  137. xhr.open("GET", url);
  138. xhr.send();
  139. xhr.onreadystatechange = function() {
  140. if(this.readyState === 4 && this.status === 200) {
  141. var i = 0;
  142. while(document.getElementsByClassName('all_page_count')[i]) {
  143. document.getElementsByClassName('all_page_count')[i].innerHTML = JSON.parse(this.responseText)['count'];
  144. i += 1;
  145. }
  146. }
  147. }
  148. }
  149. function do_open_folding(data, element = '') {
  150. var fol = document.getElementById(data);
  151. if(fol.style.display === '' || (fol.style.display === 'inline-block' || fol.style.display === 'block')) {
  152. document.getElementById(data).style.display = 'none';
  153. } else {
  154. document.getElementById(data).style.display = 'block';
  155. }
  156. if(element != '') {
  157. var fol_data = element.innerHTML;
  158. if(fol_data != '(-)') {
  159. element.innerHTML = '(-)';
  160. } else {
  161. element.innerHTML = '(+)';
  162. }
  163. }
  164. }
  165. function do_open_foot(name, num = 0) {
  166. var found_include = name.match(/^(include_(?:[0-9]+)\-)/);
  167. if(found_include) {
  168. var include_name = name.replace(/^(?:include_(?:[0-9]+)\-)/, '');
  169. var front_data = found_include[1];
  170. } else {
  171. var include_name = name;
  172. var front_data = '';
  173. }
  174. if(
  175. document.cookie.match(main_css_regex_data('main_css_footnote_set')) &&
  176. document.cookie.match(main_css_regex_data('main_css_footnote_set'))[1] === '1'
  177. ) {
  178. if(num === 1) {
  179. document.getElementById(front_data + 'r' + include_name).focus();
  180. } else {
  181. var get_data = document.getElementById(front_data + include_name).innerHTML;
  182. var org_data = document.getElementById(front_data + 'd' + include_name).innerHTML;
  183. if(org_data === '') {
  184. document.getElementById(front_data + 'd' + include_name).innerHTML = '' +
  185. '<a href="#' + front_data + 'c' + include_name + '">(Go)</a> ' + get_data +
  186. '';
  187. document.getElementById(front_data + 'd' + include_name).className = 'spead_footnote';
  188. } else {
  189. document.getElementById(front_data + 'd' + include_name).innerHTML = '';
  190. document.getElementById(front_data + 'd' + include_name).className = '';
  191. }
  192. }
  193. } else {
  194. document.getElementById(front_data + 'r' + include_name).style.color = 'red';
  195. document.getElementById(front_data + 'c' + include_name).style.color = (num === 1 ? 'inherit' : 'red');
  196. document.getElementById(front_data + (num === 1 ? 'r' : 'c') + include_name).focus();
  197. }
  198. }