Skip to content

Commit 19e9dba

Browse files
authored
Added file features
Now you don't need a text editor
1 parent 5e1f085 commit 19e9dba

File tree

1 file changed

+89
-7
lines changed

1 file changed

+89
-7
lines changed

index.htm

+89-7
Original file line numberDiff line numberDiff line change
@@ -8787,6 +8787,80 @@
87878787

87888788
<script type="text/javascript">//<![CDATA[
87898789
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+
87908864
// 0x0000 - 0x18ff => 0x3400 - 0x4cff
87918865
// 0x1900 - 0x69ff => 0x4e00 - 0x9eff
87928866
// 0x6a00 - 0x8000 => 0xac00 - 0xc200
@@ -9166,22 +9240,30 @@
91669240
<body>
91679241
<div>
91689242
<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>
91709244
<br>
91719245
</div>
91729246
<input id="filePicker" type="file"><textarea id="ascii85password">Enter a password here before uploading.</textarea>
91739247
<br>
91749248
<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>
91779255
</div>
91789256
</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>
91809263
<textarea id="filename">output.bin</textarea>
91819264
<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+
91859267
<script>
91869268
// tell the embed parent frame the height of the content
91879269
if (window.parent && window.parent.parent){

0 commit comments

Comments
 (0)