index.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="apple-mobile-web-app-capable" content="yes" />
  5. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1" />
  6. <meta charset="UTF-8">
  7. <meta name="theme-color" content="#4b75ff">
  8. <link rel="stylesheet" href="../script/semantic/semantic.min.css">
  9. <link rel="stylesheet" href="../script/ao.css">
  10. <script src="../script/jquery.min.js"></script>
  11. <script src="../script/ao_module.js"></script>
  12. <script src="../script/semantic/semantic.min.js"></script>
  13. <script src="qr/qrious.min.js"></script>
  14. <title>Web Downloader</title>
  15. <style>
  16. body {
  17. background-color: rgba(250, 250, 250, 0.8);
  18. }
  19. @supports (-webkit-backdrop-filter: none) or (backdrop-filter: none) {
  20. body {
  21. -webkit-backdrop-filter: blur(10px);
  22. backdrop-filter: blur(10px);
  23. background-color: rgba(250, 250, 250, 0.7);
  24. }
  25. }
  26. @font-face {
  27. font-family: 'TaipeiSansTCBeta';
  28. src: url("../script/font/TaipeiSansTCBeta-Regular.ttf");
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <br>
  34. <div class="ui container">
  35. <h3 class="ui header">
  36. <i class="download icon"></i>
  37. <div class="content">
  38. Web Downloader
  39. <div class="sub header">Copy and Paste URL to download</div>
  40. </div>
  41. </h3>
  42. <form class="ui form">
  43. <div class="field">
  44. <label>URL</label>
  45. <input type="text" id="url" placeholder="http://example.com/myfile.txt">
  46. </div>
  47. <div class="field">
  48. <label>Save Location</label>
  49. <div class="ui icon input">
  50. <input type="text" id="filepath" placeholder="user:/Download/">
  51. <i class="circular open folder link icon" id="filepathbtn" onclick="selectSaveLocation()"></i>
  52. </div>
  53. </div>
  54. </form>
  55. <br>
  56. <button class="ui primary button" id="downloadbtn" onclick="initDownload()">Download</button>
  57. <!-- <button class="ui black button">Download on new tab</button>-->
  58. <br><br>
  59. <p id="status">Ready.</p>
  60. </div>
  61. <script>
  62. //Init windows events
  63. ao_module_setFixedWindowSize();
  64. function selectSaveLocation() {
  65. var filename = decodeURI($("#url").val().split("/").pop().split("?").shift());
  66. option = {
  67. defaultName: filename //Default filename used in new operation
  68. }
  69. ao_module_openFileSelector(fileSelected, "user:/Download", "new", false, option);
  70. }
  71. function fileSelected(filedata) {
  72. var filepath = filedata[0].filepath;
  73. $("#filepath").val(filepath);
  74. }
  75. function initDownload() {
  76. //check if path is empty before executing
  77. if ($("#filepath").val() == "") {
  78. var defaultFilename = decodeURI($("#url").val().split("/").pop().split("?").shift());
  79. $("#filepath").val("user:/Download/" + defaultFilename);
  80. }
  81. //declare variable
  82. var link = $("#url").val();
  83. var filepath = getfilepath($("#filepath").val());
  84. var filename = $("#filepath").val().split("/").pop();
  85. //error handler
  86. if (link == "") {
  87. $("#status").html("Error: Invalid URL.");
  88. return
  89. }
  90. if (filepath == "" || filename == "") {
  91. $("#status").html("Error: Invalid filepath.");
  92. return
  93. }
  94. //set the status
  95. fieldDisabled(true);
  96. $("#status").html('<i class="spinner loading icon "></i> Downloading...');
  97. //send the AJAX request to the serevr
  98. $.post("/system/ajgi/interface?script=Web Downloader/agi/download.agi", {
  99. link: link,
  100. filename: filename,
  101. filepath: filepath
  102. }, function(data) {
  103. //set the status
  104. fieldDisabled(false);
  105. $("#status").html('Downloaded in ' + filepath);
  106. });
  107. }
  108. function fieldDisabled(boolean) {
  109. $("#url").attr("disabled", boolean);
  110. $("#filepath").attr("disabled", boolean);
  111. $("#filepathbtn").attr("disabled", boolean);
  112. $("#downloadbtn").attr("disabled", boolean);
  113. }
  114. //handle the filepath
  115. function getfilepath(beforeProcessedPath) {
  116. var pathArray = beforeProcessedPath.split("/");
  117. var processedPath = "";
  118. for (var i = 0; i < pathArray.length - 1; i++) {
  119. processedPath += pathArray[i] + "/";
  120. }
  121. return processedPath;
  122. }
  123. </script>
  124. </body>
  125. </html>