slitaz-forge diff mirror/floppies/format.js @ rev 716
mirror/floppies: multi-format support
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Jul 23 16:41:12 2021 +0000 (2021-07-23) |
parents | |
children | 291e2d88bab3 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mirror/floppies/format.js Fri Jul 23 16:41:12 2021 +0000 1.3 @@ -0,0 +1,79 @@ 1.4 +window.URL = window.URL || window.webkitURL; 1.5 +function download(ref, range, name) { 1.6 + var xhr = new XMLHttpRequest(); 1.7 + 1.8 + xhr.open('GET', ref, true); 1.9 + xhr.setRequestHeader("Range", "bytes="+range); 1.10 + xhr.responseType = 'blob'; 1.11 + xhr.onload = function () { 1.12 + var a = document.createElement('a'), file; 1.13 + file = new Blob([xhr.response], { type : 'application/octet-stream' }); 1.14 + a.href = window.URL.createObjectURL(file); 1.15 + a.download = name; 1.16 + a.click(); 1.17 + }; 1.18 + xhr.send(); 1.19 +} 1.20 + 1.21 +function format(size) { 1.22 + var max = sets[sets.length-1]; 1.23 + var cols = Math.floor(Math.sqrt(max/size)+2); 1.24 + var lines = Math.floor(((max/size)+1)/cols+1); 1.25 + var e = document.getElementById('floppies'); 1.26 + var s, i, j, ofs, fd, fds, curset; 1.27 + for (i = 0, ofs = 0, curset = 0, fd = 1, s = ""; i < lines; i++) { 1.28 + s += "<tr>"; 1.29 + for (j = 0; j < cols; j++) { 1.30 + fds = ""+fd; if (fd < 100) fds = "0"+fds; if (fd < 10) fds = "0"+fds; 1.31 + s += "<td>"; 1.32 + if (ofs < max) { 1.33 + s += "<a href=\"javascript:download('"+dir+"/fd.img', '"+ofs+"-"; 1.34 + ofs = Number.parseInt(ofs)+Number.parseInt(size); 1.35 + s += (ofs-1)+"', 'fd"+fds+".img')\">fd"+fds+"</a>"; 1.36 + if (ofs >= sets[curset]) { 1.37 + curset++; 1.38 + fd = (Math.floor(fd/100)+1)*100; 1.39 + } else fd++; 1.40 + } 1.41 + if (i == lines-1 && j == cols-1) { 1.42 + s += "<a href=\""+dir+"/"+size+"/md5sum\">md5</a>" 1.43 + } 1.44 + s += "</td>"; 1.45 + } 1.46 + s += "</tr>"; 1.47 + } 1.48 + e.innerHTML = s; 1.49 + for (i = 0, ofs = 0, curset = 0, fd = 0; ofs < max;) { 1.50 + i++; fd++; 1.51 + ofs = Number.parseInt(ofs)+Number.parseInt(size); 1.52 + if (ofs >= sets[curset]) { 1.53 + fds = ""+fd; if (fd < 100) fds = "0"+fds; if (fd < 10) fds = "0"+fds; 1.54 + e = document.getElementById('cnt'+curset); 1.55 + if (e) e.innerHTML = i; 1.56 + e = document.getElementById('last'+curset); 1.57 + if (e) e.innerHTML = fds; 1.58 + curset++; 1.59 + fd = (Math.floor(fd/100)+1)*100-1; 1.60 + } 1.61 + } 1.62 +} 1.63 + 1.64 +var e = document.getElementById('format'); 1.65 +try { 1.66 + var dummy = new Blob(); 1.67 + e.innerHTML="<select onChange='format(this.value)' style='background: #666; color: #FFF;'>" + 1.68 + "<option value='368640' title='/dev/fd0h360 (2,20) or /dev/fd0d360 (2,4) 5¼'>360K</option>" + 1.69 + "<option value='737280' title='/dev/fd0u720 3½ DD (2,16)'>720K</option>" + 1.70 + "<option value='819200' title='/dev/fd0u800 3½ DD (2,120)'>800K</option>" + 1.71 + "<option value='1228800' title='/dev/fd0h1200 5¼ (2,8)'>1.2MB</option>" + 1.72 + "<option value='1474560' title='/dev/fd0u1440 3½ HD (2,28) or /dev/fd0h1440 5¼ (2,40)' selected>1.44MB</option>" + 1.73 + "<option value='1638400' title='/dev/fd0u1600 3½ HD (2,124) or /dev/fd0h1600 5¼ (2,92)'>1.60MB</option>" + 1.74 + "<option value='1720320' title='/dev/fd0u1680 3½ HD (2,44)'>1.68MB</option>" + 1.75 + "<option value='1966080' title='/dev/fd0u1920 3½ HD (2,100)'>1.92MB</option>" + 1.76 + "<option value='2949120' title='/dev/fd0u2880 3½ ED (2,32)'>2.88MB</option>" + 1.77 + "<option value='3932160' title='/dev/fd0u3840 3½ ED (2,112)'>3.84MB</option>" + 1.78 + "</select>"; 1.79 +} 1.80 +catch (err) { 1.81 + e.innerHTML="1.44MB"; 1.82 +}