downloads.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <!DOCTYPE html>
  2. <html dir="ltr" lang="en" i18n-processed="">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>下载</title>
  6. <link rel="stylesheet" href="shared.css">
  7. <link rel="stylesheet" href="other.css">
  8. <script type="text/javascript" src="jquery-1.10.2.min.js"></script>
  9. </head>
  10. <body>
  11. <header>
  12. <h1>下载</h1>
  13. <input id="term" type="search" tabindex="1" autofocus="" incremental="" placeholder="Search downloads" hidden>
  14. </header>
  15. <div class="main">
  16. <div class="summary" id="downloads-summary">
  17. <span id="downloads-summary-text"></span>
  18. <span id="downloads-actions">
  19. <a is="action-link" id="open-downloads-folder" tabindex="0" role="link" hidden>Open downloads folder</a>
  20. <a is="action-link" id="clear-all" tabindex="0" role="link" hidden>Clear all</a>
  21. </span>
  22. </div>
  23. <div id="downloads-display">
  24. <div id="template" class="download" hidden>
  25. <div class="date-container">
  26. <div class="since">Today</div>
  27. <div class="date">Jan 24, 2016</div>
  28. </div>
  29. <div class="safe">
  30. <div class="progress background" hidden=""></div>
  31. <canvas class="progress" hidden=""></canvas>
  32. <img class="icon" alt="" src="">
  33. <div class="title-area">
  34. <a is="action-link" class="name" focus-type="name" tabindex="0" role="link" href="http://x.org/x.zip" hidden="">x.xip</a>
  35. <span class="name">x.zip</span>
  36. <span class="status">Status</span>
  37. </div>
  38. <div class="url-container">
  39. <a class="src-url" target="_blank" focus-type="url" href="http://x.org/x.zip" tabindex="0">http://x.org/x.zip</a>
  40. </div>
  41. <div class="controls">
  42. <a is="action-link" class="show" focus-type="show-retry" tabindex="0" role="link" hidden="">在文件夹中显示</a>
  43. <a class="retry" focus-type="show-retry" download="" href="http://x.org/x.zip" hidden="" tabindex="0">重试</a>
  44. <a is="action-link" class="pause" focus-type="pause-resume" tabindex="0" role="link" hidden="">暂停</a>
  45. <a is="action-link" class="resume" focus-type="pause-resume" tabindex="0" role="link" hidden="">恢复</a>
  46. <a is="action-link" class="remove" focus-type="remove-discard" tabindex="0" role="link" hidden>在列表中清除</a>
  47. <a is="action-link" class="cancel" focus-type="cancel" tabindex="0" role="link">取消</a>
  48. <span class="controlled-by" hidden="">下载于 <a>$1</a></span>
  49. </div>
  50. </div>
  51. <div class="dangerous" hidden>
  52. <img class="icon" alt="">
  53. <div class="description"></div>
  54. <div class="controls">
  55. <a is="action-link" class="restore" focus-type="restore-save" tabindex="0" role="link">此类型的文件可能会影响你的电脑</a>
  56. <a is="action-link" class="remove" focus-type="discard" tabindex="0" role="link">从列表中移出</a>
  57. </div>
  58. <button class="save" focus-type="restore-save" tabindex="0">保留</button>
  59. <button class="discard" focus-type="remove-discard" tabindex="0">放弃</button>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. <script type="text/javascript">
  65. (async function() {
  66. var $container;
  67. var $template;
  68. var timer;
  69. await CefSharp.BindObjectAsync("host");
  70. $(document).ready(function() {
  71. $container = $("#downloads-display");
  72. $template = $("#template");
  73. UpdateList();
  74. timer = setInterval(UpdateList, 500);
  75. });
  76. function formatBytes(bytes, decimals) {
  77. if (bytes == 0) return '0 Byte';
  78. var k = 1000;
  79. var dm = decimals + 1 || 3;
  80. var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  81. var i = Math.floor(Math.log(bytes) / Math.log(k));
  82. return (bytes / Math.pow(k, i)).toPrecision(dm) + ' ' + sizes[i];
  83. }
  84. String.prototype.between = function(prefix, suffix) {
  85. s = this;
  86. var i = s.indexOf(prefix);
  87. if (i >= 0) {
  88. s = s.substring(i + prefix.length);
  89. } else {
  90. return '';
  91. }
  92. if (suffix) {
  93. i = s.indexOf(suffix);
  94. if (i >= 0) {
  95. s = s.substring(0, i);
  96. } else {
  97. return '';
  98. }
  99. }
  100. return s;
  101. }
  102. Date.prototype.format = function(format) //author: meizz
  103. {
  104. var o = {
  105. "M+": this.getMonth() + 1, //month
  106. "d+": this.getDate(), //day
  107. "h+": this.getHours(), //hour
  108. "m+": this.getMinutes(), //minute
  109. "s+": this.getSeconds(), //second
  110. "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
  111. "S": this.getMilliseconds() //millisecond
  112. }
  113. if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
  114. (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  115. for (var k in o)
  116. if (new RegExp("(" + k + ")").test(format))
  117. format = format.replace(RegExp.$1,
  118. RegExp.$1.length == 1 ? o[k] :
  119. ("00" + o[k]).substr(("" + o[k]).length));
  120. return format;
  121. }
  122. function getDate(dt) {
  123. return eval("new " + dt.between("/", "/"));
  124. }
  125. function UpdateItem(item) {
  126. var $item;
  127. var id = "d" + item.Id;
  128. $item = $("#" + id);
  129. //Add item if it does not exist
  130. if ($item.length == 0) {
  131. $item = $($template[0].outerHTML);
  132. $container.prepend($item);
  133. // show it
  134. $item.removeAttr("hidden");
  135. // add basic stuff
  136. $item.attr("id", id);
  137. $item.find("a.cancel").click(function() {
  138. host.cancelDownload(item.Id);
  139. });
  140. // icon
  141. $item.find("img.icon").attr("src", "ttBrowser://fileicon/" + item.SuggestedFileName);
  142. // name
  143. if (item.SuggestedFileName != "") $item.find("span.name").text(item.SuggestedFileName);
  144. $item.find("a.src-url").attr("href", item.Url).text(item.Url);
  145. $item.find("a.cancel").removeAttr("hidden");
  146. // date
  147. var startTime = new Date(item.StartTime);
  148. $item.find("div.since").text(startTime.format("yyyy.MM.dd"));
  149. $item.find("div.date").text(startTime.format("hh:mm:ss"));
  150. }
  151. var progress = "";
  152. if (item.IsInProgress) {
  153. progress = formatBytes(item.CurrentSpeed) + "/s - " + formatBytes(item.ReceivedBytes, 2);
  154. if (item.TotalBytes > 0) progress += " of " + formatBytes(item.TotalBytes, 2);
  155. if (item.PercentComplete > 0) progress += " (" + item.PercentComplete + "%)";
  156. } else {
  157. if (item.IsComplete) progress = "下载完成";
  158. else if (item.IsCancelled) progress = "已取消";
  159. $item.find("a.cancel").attr("hidden", "");
  160. }
  161. $item.find("span.status").text(progress);
  162. }
  163. function UpdateList() {
  164. host.getDownloads().then(function(res) {
  165. var list = JSON.parse(res);
  166. $.each(list, function(key, item) {
  167. UpdateItem(item.v);
  168. });
  169. });
  170. }
  171. })();
  172. </script>
  173. </body>
  174. </html>