@@ 144,6 144,7 @@
const dataEntry = document.getElementById('data');
dataEntry.addEventListener('change', onChange);
dataEntry.addEventListener('keyup', onChange);
+ dataEntry.addEventListener('paste', onDataPaste);
const formatEntry = document.getElementById('struct');
formatEntry.addEventListener('change', onChange);
@@ 152,6 153,34 @@
onChange();
});
+ function onDataPaste(event) {
+ // The paste event fires before the textarea gets the new value, run this slightly later
+ setTimeout(function () {
+ const dataEntry = document.getElementById('data');
+ let pasted = dataEntry.value.trim();
+ if (pasted.startsWith("b'") || pasted.startsWith('b"')) {
+ pasted = pasted.slice(2, -1);
+ let result = '';
+ while (pasted.length > 0) {
+ if (pasted.startsWith('\\x')) {
+ let num = pasted.substring(2, 4);
+ pasted = pasted.substring(4);
+ result += num + ' ';
+ } else if (pasted.startsWith('\\')) {
+ let char = pasted.charCodeAt(1);
+ pasted = pasted.substring(2);
+ result += char.toString(16).padStart(2, '0') + ' ';
+ } else {
+ let char = pasted.charCodeAt(0);
+ pasted = pasted.substring(1);
+ result += char.toString(16).padStart(2, '0') + ' ';
+ }
+ }
+ dataEntry.value = result.trim();
+ }
+ }, 1);
+ }
+
function updateData(format) {
const dataEntry = document.getElementById('data');
let data = dataEntry.value;