|
8787 | 8787 |
|
8788 | 8788 | <script type="text/javascript">//<![CDATA[
|
8789 | 8789 | window.addEvent('load', function() {
|
| 8790 | + |
| 8791 | +document.getElementById("fileToRead").addEventListener("change",function(){ |
| 8792 | + var file = this.files[0]; |
| 8793 | + |
| 8794 | + if (file) { |
| 8795 | + var reader = new FileReader(); |
| 8796 | + |
| 8797 | + reader.onload = function (evt) { |
| 8798 | + console.log(evt); |
| 8799 | + document.getElementById("textbox").value = endianMark + evt.target.result; |
| 8800 | + }; |
| 8801 | + |
| 8802 | + reader.onerror = function (evt) { |
| 8803 | + console.error("An error ocurred reading the file",evt); |
| 8804 | + }; |
| 8805 | + |
| 8806 | + reader.readAsText(file, "UTF-16BE"); |
| 8807 | + } |
| 8808 | +},false); |
| 8809 | + |
| 8810 | +document.getElementById('download').addEventListener('click', function(){ |
| 8811 | +if (document.getElementById("base64textarea").value.includes(endianMark)) { |
| 8812 | + |
| 8813 | + downloadUtf16(document.getElementById("base64textarea").value.substring(1), document.getElementById("B3Kfilename").value) |
| 8814 | + } |
| 8815 | + else { |
| 8816 | + downloadUtf16(document.getElementById("base64textarea").value, document.getElementById("B3Kfilename").value) |
| 8817 | + } |
| 8818 | + |
| 8819 | +}); |
| 8820 | + |
| 8821 | +function downloadUtf16(str, filename) { |
| 8822 | + |
| 8823 | + // ref: https://stackoverflow.com/q/6226189 |
| 8824 | + var charCode, byteArray = []; |
| 8825 | + |
| 8826 | + // BE BOM |
| 8827 | + byteArray.push(254, 255); |
| 8828 | + |
| 8829 | + // LE BOM |
| 8830 | + // byteArray.push(255, 254); |
| 8831 | + |
| 8832 | + for (var i = 0; i < str.length; ++i) { |
| 8833 | + |
| 8834 | + charCode = str.charCodeAt(i); |
| 8835 | + |
| 8836 | + // BE Bytes |
| 8837 | + byteArray.push((charCode & 0xFF00) >>> 8); |
| 8838 | + byteArray.push(charCode & 0xFF); |
| 8839 | + |
| 8840 | + // LE Bytes |
| 8841 | + // byteArray.push(charCode & 0xff); |
| 8842 | + // byteArray.push(charCode / 256 >>> 0); |
| 8843 | + } |
| 8844 | + |
| 8845 | + var blob = new Blob([new Uint8Array(byteArray)], {type:'text/plain;charset=UTF-16BE;'}); |
| 8846 | + var blobUrl = URL.createObjectURL(blob); |
| 8847 | + |
| 8848 | + // ref: https://stackoverflow.com/a/18197511 |
| 8849 | + var link = document.createElement('a'); |
| 8850 | + link.href = blobUrl; |
| 8851 | + link.download = filename; |
| 8852 | + |
| 8853 | + if (document.createEvent) { |
| 8854 | + var event = document.createEvent('MouseEvents'); |
| 8855 | + event.initEvent('click', true, true); |
| 8856 | + link.dispatchEvent(event); |
| 8857 | + } else { |
| 8858 | + link.click(); |
| 8859 | + } |
| 8860 | +} |
| 8861 | + |
| 8862 | + |
| 8863 | + |
8790 | 8864 | // 0x0000 - 0x18ff => 0x3400 - 0x4cff
|
8791 | 8865 | // 0x1900 - 0x69ff => 0x4e00 - 0x9eff
|
8792 | 8866 | // 0x6a00 - 0x8000 => 0xac00 - 0xc200
|
|
9166 | 9240 | <body>
|
9167 | 9241 | <div>
|
9168 | 9242 | <div>
|
9169 |
| - <label for="filePicker">Choose or drag a (tar) file:</label> |
| 9243 | + <label for="filePicker">Choose or drag a (tar) file to encode:</label> |
9170 | 9244 | <br>
|
9171 | 9245 | </div>
|
9172 | 9246 | <input id="filePicker" type="file"><textarea id="ascii85password">Enter a password here before uploading.</textarea>
|
9173 | 9247 | <br>
|
9174 | 9248 | <div>
|
9175 |
| - <h1>Base32768 encoded version</h1> |
9176 |
| - <textarea id="base64textarea" placeholder="Base32768 will appear here" cols="50" rows="15"></textarea> |
| 9249 | + <h1>BWTC32Key encoded version</h1> |
| 9250 | + <textarea id="base64textarea" placeholder="Base32768 will appear here" cols="50" rows="15"></textarea><br> |
| 9251 | + <p>B3K filename:</p> |
| 9252 | + |
| 9253 | + <textarea id="B3Kfilename">myFile.B3K</textarea> |
| 9254 | + <button id="download">Download .B3K of above textbox</button> |
9177 | 9255 | </div>
|
9178 | 9256 | </div>
|
9179 |
| -<textarea id="textbox">Type Base32768 encoded text here to decode</textarea><button id="create">Click to decode file</button><br /> |
| 9257 | +<h3>Decoding:</h3> |
| 9258 | +<p>Upload a B3K file here:</p> |
| 9259 | +<input type="file" id="fileToRead"> |
| 9260 | +<br> |
| 9261 | +<textarea id="textbox" cols="25" >Type BWTC32Key-encoded text here to decode</textarea><button id="create">Click to decode file</button><br /> |
| 9262 | +<p>Output's Filename & MIMEtype</p> |
9180 | 9263 | <textarea id="filename">output.bin</textarea>
|
9181 | 9264 | <textarea id="filetype">application/octet-stream</textarea><br />
|
9182 |
| - <a download="output.bin" id="downloadlink" style="display: none">Download</a> |
9183 |
| - |
9184 |
| - |
| 9265 | + <a download="output.bin" id="downloadlink" style="display: none">Download decoded file</a> |
| 9266 | + |
9185 | 9267 | <script>
|
9186 | 9268 | // tell the embed parent frame the height of the content
|
9187 | 9269 | if (window.parent && window.parent.parent){
|
|
0 commit comments