init.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. const dongwaa_webDB_URL = 'https://dongwaa.cakko.ml/'
  2. const bottombarbuttons = [
  3. 'Browse,/dongwaa/_browse/,' + resourceNETpath + 'image/browse.png',
  4. 'Today,/dongwaa/,' + resourceNETpath + 'image/dongwaa.png',
  5. 'Library,/dongwaa/_library/,' + resourceNETpath + 'image/dig.png',
  6. 'Search,/dongwaa/_dig/,' + resourceNETpath + 'image/search.png',
  7. 'Settings,/dongwaa/_setting/,' + resourceNETpath + 'image/settings.png'
  8. ]
  9. function init(path) {
  10. if (path == undefined || path === '/') {
  11. return `<meta http-equiv="refresh" content="0;URL=/dongwaa/">`
  12. } else if (path === '/dongwaa/' || path.startsWith('/dongwaa/_')) {
  13. if (path === '/dongwaa/') {
  14. return `<div class="edge2edge card">[home] /dongwaa/</div>` + renderBottomBar(path)
  15. } else if (path.startsWith('/dongwaa/_dig/')) {
  16. return `<div class="edge2edge card">` + path + '</div>' + renderBottomBar(path)
  17. } else if (path.startsWith('/dongwaa/_browse/')) {
  18. return `<div class="edge2edge card" id="dump">` + path + '</div>' + renderBottomBar(path)
  19. } else if (path.startsWith('/dongwaa/_library/')) {
  20. return `<div class="edge2edge card">` + path + '</div>' + renderBottomBar(path)
  21. } else if (path.startsWith('/dongwaa/_setting/')) {
  22. return `<div class="edge2edge card">` + path + '</div>' + renderBottomBar(path)
  23. } else {
  24. return `<meta http-equiv="refresh" content="0;URL=/dongwaa/">`
  25. }
  26. } else if (path.startsWith('/dongwaa/')) {
  27. return `` + renderTopBar('...', '', '', true) + `<div id="content"></div>
  28. <!-- <button type="button" onclick="LoadingStatus('show')">show load</button>
  29. <button type="button" onclick="LoadingStatus('hide')">hide load</button>
  30. <button type="button" onclick="LoadingStatus('success')">success load</button>
  31. <button type="button" onclick="LoadingStatus('warning', false, 'Warning')">warning load</button>
  32. <button type="button" onclick="LoadingStatus('error', false, 'Error', 'Sorewa error message desu')">error load</button> -->`
  33. }
  34. }
  35. function exe(path) {
  36. if (!path.startsWith('/dongwaa/_') && path != '/dongwaa/' && path.startsWith('/dongwaa/')) { //dongwaa pages
  37. LoadingStatus("show")
  38. var dwid_url = path.substring(9)
  39. fetch(dongwaa_webDB_URL + '!dwfs/' + path.split('/')[2])
  40. .then(r => r.json())
  41. .then(dwfs_resp => {
  42. if (dwfs_resp.status == 200) {
  43. init_data(dwfs_resp)
  44. } else {
  45. var dwid_guess = decodeURI(dwid_url).split('/')[0].substring(decodeURI(dwid_url).split('/')[0].split(' ')[0].length + 1)
  46. var guess = dwid_guess.split(' ')[0]
  47. var guess_dwss = ""
  48. try { guess_dwss = dwid_guess.split(' ')[1] } catch (error) { guess_dwss = undefined }
  49. if (guess == '') {on9jai()} else {
  50. fetch(dongwaa_webDB_URL + '!dwfs/' + guess)
  51. .then(response => response.json())
  52. .then(dwfs_resp => {
  53. if (dwfs_resp.status == 200 && (dwfs_resp.dwfs == decodeURI(dwid_url).split('/')[0] || dwfs_resp.dwfs.indexOf(decodeURI(dwid_url).split('/')[0]) > -1)) {
  54. history.replaceState(null, null, '/dongwaa/'.concat(guess).concat((guess_dwss != undefined) ? '/'.concat(guess_dwss) : ''))
  55. dwid_url = (guess_dwss != undefined) ? guess.concat('/').concat(guess_dwss) : guess ;
  56. init_data(dwfs_resp)
  57. } else {
  58. on9jai()
  59. }
  60. })
  61. }
  62. }
  63. })
  64. .catch(function (err) {
  65. console.log('[!dwfs] error: ' + err)
  66. setTimeout(() => {
  67. LoadingStatus("error", true, "Failed to load", err)
  68. }, 1000)
  69. });
  70. function init_data(dwfs_resp) {
  71. var target_dw = '';
  72. var noSeasonOne = false;
  73. var dwss_in_dwfs_pos = 0;
  74. var url_dwss = decodeURI(dwid_url.split('/')[0]);
  75. if (dwid_url.split('/')[1] != undefined) { url_dwss += ' '.concat(dwid_url.split('/')[1]) };
  76. if (Array.isArray(dwfs_resp.dwfs)) { //returned array
  77. dwfs_resp.dwfs.sort();
  78. if (dwid_url.split('/')[1] == '') {
  79. target_dw = dwfs_resp.dwfs[0];
  80. dwss_in_dwfs_pos = 0;
  81. } else {
  82. target_dw = dwfs_resp.dwfs.find(l => l.endsWith(url_dwss));
  83. dwss_in_dwfs_pos = dwfs_resp.dwfs.findIndex(dwfsX => dwfsX === target_dw);
  84. };
  85. } else { //returned single
  86. target_dw = dwfs_resp.dwfs;
  87. if (target_dw.split(' ')[2] != undefined) { noSeasonOne = true } //check should expect season 1
  88. }
  89. download_data(target_dw, dwfs_resp, dwss_in_dwfs_pos, noSeasonOne, false)
  90. }
  91. function download_data(target_dw, dwfs_resp, dwss_in_dwfs_pos, noSeasonOne, try_direct) {
  92. fetch(dongwaa_webDB_URL + '!dw/' + target_dw)
  93. .then(r => r.json())
  94. .then(dw_resp => {
  95. if (dw_resp.status == 200) {
  96. document.getElementById('topbar_title').innerText = popArray[popArray.length - 1].split('/')[0]
  97. document.getElementById('content').innerHTML = '<div class="edge2edge card">' + JSON.stringify(dw_resp) + '</div><div class="edge2edge card" id="dump"></div>'
  98. fetch("/system/ajgi/interface?script=dongwaa/agi.js", {method: 'POST', body: 'action=listDir&path=' + popArray[popArray.length - 1], headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}})
  99. .then(r => r.json())
  100. .then(data => {
  101. if (data.length > 0) {
  102. data.forEach(dwid => {
  103. document.getElementById('dump').innerHTML += '<br><a class="aobh" href="/dongwaa/_browse/' + dwid.substring(9) + '">' + dwid + '</a>'
  104. });
  105. postCleanup();
  106. } else {
  107. document.getElementById('dump').innerHTML += '<br><i>no more subfolders</i>'
  108. }
  109. fetch("/system/ajgi/interface?script=dongwaa/agi.js", {method: 'POST', body: 'action=listFile&path=' + popArray[popArray.length - 1], headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}})
  110. .then(r => r.json())
  111. .then(r => r.filter(v => !data.includes(v)))
  112. .then(datax => {
  113. if (datax.length > 0) {
  114. document.getElementById('dump').innerHTML += '<hr><ui>'
  115. datax.forEach(dwid => {
  116. document.getElementById('dump').innerHTML += '<li>' + dwid + '</li>'
  117. });
  118. document.getElementById('dump').innerHTML += '</ui>'
  119. } else {
  120. document.getElementById('dump').innerHTML += '<br><i>no files inside</i>'
  121. }
  122. postCleanup();
  123. })
  124. })
  125. LoadingStatus("hide")
  126. } else { on9jai() }
  127. })
  128. .catch(function (err) {
  129. console.log('[!dwpage] error: ' + err)
  130. LoadingStatus("error", true, "Failed to load", err)
  131. });
  132. }
  133. } else if (path.startsWith('/dongwaa/_browse/')) { //dongwaa browse
  134. path.split('/').forEach(path_dwid => {
  135. path_dwid = path_dwid.split('{')[0].split('[')[0]
  136. console.log(path_dwid)
  137. if (!!path_dwid && path_dwid != 'dongwaa' && path_dwid != '_browse') {
  138. try {
  139. fetch(dongwaa_webDB_URL + "!dwdig/" + path_dwid)
  140. .then(r => r.json())
  141. .then(data => {
  142. if (data.status === 200) {
  143. if (data.result.length > 1) {
  144. } else {
  145. popArray.push(path.substring(17))
  146. boot('/dongwaa/' + data.result, true)
  147. return
  148. }
  149. } else {return}
  150. })
  151. } catch (error) {return}
  152. }
  153. });
  154. document.getElementById('dump').innerHTML += (path === '/dongwaa/_browse/') ? '<br>' : '<br><button onclick="window.history.back();" class="acss aobh no_print" style="padding:0.5em;font-size:16px;white-space:pre;transition-duration:0s" id="btn_back" tabindex="0" title="back"><b>く back</b></button>'
  155. fetch("/system/ajgi/interface?script=dongwaa/agi.js", {method: 'POST', body: 'action=listDir&path=' + path.substring(17), headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}})
  156. .then(r => r.json())
  157. .then(data => {
  158. if (data.length > 0) {
  159. data.forEach(dwid => {
  160. document.getElementById('dump').innerHTML += '<br><a class="aobh" href="/dongwaa/_browse/' + dwid.substring(9) + '">' + dwid + '</a>'
  161. });
  162. postCleanup();
  163. } else {
  164. document.getElementById('dump').innerHTML += '<br><i>no more subfolders</i>'
  165. }
  166. fetch("/system/ajgi/interface?script=dongwaa/agi.js", {method: 'POST', body: 'action=listFile&path=' + path.substring(17), headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}})
  167. .then(r => r.json())
  168. .then(r => r.filter(v => !data.includes(v)))
  169. .then(datax => {
  170. if (datax.length > 0) {
  171. document.getElementById('dump').innerHTML += '<hr><ui>'
  172. datax.forEach(dwid => {
  173. document.getElementById('dump').innerHTML += '<li>' + dwid + '</li>'
  174. });
  175. document.getElementById('dump').innerHTML += '</ui>'
  176. } else {
  177. document.getElementById('dump').innerHTML += '<br><i>no files inside</i>'
  178. }
  179. postCleanup();
  180. })
  181. })
  182. }
  183. }