index.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. </style>
  27. </head>
  28. <body>
  29. <br>
  30. <div class="ui container">
  31. <h3 class="ui header">
  32. <i class="download icon"></i>
  33. <div class="content">
  34. Web Downloader
  35. <div class="sub header">Copy and Paste URL to download</div>
  36. </div>
  37. </h3>
  38. <form class="ui form">
  39. <div class="field">
  40. <label>URL</label>
  41. <input type="text" id="url" placeholder="http://example.com/myfile.txt">
  42. </div>
  43. <div class="field">
  44. <label>Save Location</label>
  45. <div class="ui icon input">
  46. <input type="text" id="filepath" placeholder="user:/Download/">
  47. <i class="circular open folder link icon" id="filepathbtn" onclick="selectSaveLocation()"></i>
  48. </div>
  49. </div>
  50. </form>
  51. <br>
  52. <button class="ui primary button" id="downloadbtn" onclick="initDownload()">Download</button>
  53. <!-- <button class="ui black button">Download on new tab</button>-->
  54. <br><br>
  55. <p id="status">Ready.</p>
  56. </div>
  57. <script>
  58. //Init windows events
  59. ao_module_setFixedWindowSize();
  60. function selectSaveLocation() {
  61. var filename = decodeURI($("#url").val().split("/").pop().split("?").shift());
  62. option = {
  63. defaultName: filename //Default filename used in new operation
  64. }
  65. ao_module_openFileSelector(fileSelected, "user:/Download", "new", false, option);
  66. }
  67. function fileSelected(filedata) {
  68. var filepath = filedata[0].filepath;
  69. $("#filepath").val(filepath);
  70. }
  71. function initDownload() {
  72. //check if path is empty before executing
  73. if ($("#filepath").val() == "") {
  74. var defaultFilename = decodeURI($("#url").val().split("/").pop().split("?").shift());
  75. $("#filepath").val("user:/Download/" + defaultFilename);
  76. }
  77. //declare variable
  78. var link = $("#url").val();
  79. var filepath = getfilepath($("#filepath").val());
  80. var filename = $("#filepath").val().split("/").pop();
  81. //error handler
  82. if (link == "") {
  83. $("#status").html("Error: Invalid URL.");
  84. return
  85. }
  86. if (filepath == "" || filename == "") {
  87. $("#status").html("Error: Invalid filepath.");
  88. return
  89. }
  90. //set the status
  91. fieldDisabled(true);
  92. $("#status").html('<i class="spinner loading icon "></i> Downloading...');
  93. //send the AJAX request to the serevr
  94. $.post("/system/ajgi/interface?script=Web Downloader/agi/download.agi", {
  95. link: link,
  96. filename: filename,
  97. filepath: filepath
  98. }, function(data) {
  99. //set the status
  100. fieldDisabled(false);
  101. $("#status").html('Downloaded in ' + filepath);
  102. });
  103. }
  104. function fieldDisabled(boolean) {
  105. $("#url").attr("disabled", boolean);
  106. $("#filepath").attr("disabled", boolean);
  107. $("#filepathbtn").attr("disabled", boolean);
  108. $("#downloadbtn").attr("disabled", boolean);
  109. }
  110. //handle the filepath
  111. function getfilepath(beforeProcessedPath) {
  112. var pathArray = beforeProcessedPath.split("/");
  113. var processedPath = "";
  114. for (var i = 0; i < pathArray.length - 1; i++) {
  115. processedPath += pathArray[i] + "/";
  116. }
  117. return processedPath;
  118. }
  119. </script>
  120. </body>
  121. </html>