mirror of
https://github.com/Av0idD4rk/packmate.git
synced 2026-10-25 08:49:26 +00:00
Исправил (вроде) копирование, добавил копирование в Python bytes
This commit is contained in:
parent
1ad27320a7
commit
44fa9824df
@ -1,7 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="packet" :class="{'packet-incoming': isIncoming}">
|
<div class="packet" :class="{'packet-incoming': isIncoming}">
|
||||||
<div>#{{id}} at {{new Date(timestamp).toLocaleDateString('ru-RU', {month: '2-digit', day: '2-digit', hour:'2-digit', minute: '2-digit', second: '2-digit'})}}
|
<div>#{{id}} at {{new Date(timestamp).toLocaleDateString('ru-RU', {month: '2-digit', day: '2-digit', hour:'2-digit', minute: '2-digit', second: '2-digit'})}}
|
||||||
<button @click.prevent="copyContent" class="btn btn-link">Copy</button></div>
|
<button @click.prevent="copyRaw" class="btn btn-link">Copy HEX</button>
|
||||||
|
<button @click.prevent="copyPythonBytes" class="btn btn-link">Copy as Python bytes </button></div>
|
||||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-2 pb-2 mb-3 border-bottom">
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-2 pb-2 mb-3 border-bottom">
|
||||||
<pre>{{ hexdata }}</pre>
|
<pre>{{ hexdata }}</pre>
|
||||||
</div>
|
</div>
|
||||||
@ -34,18 +35,27 @@ export default {
|
|||||||
}
|
}
|
||||||
return lines.join("\n");
|
return lines.join("\n");
|
||||||
},
|
},
|
||||||
copyContent() {
|
copyPythonBytes() {
|
||||||
navigator.clipboard.writeText(
|
const data = "b'" + atob(this.$props.content)
|
||||||
atob(this.$props.content)
|
.split('')
|
||||||
.split('')
|
.map((aChar) => {
|
||||||
.map(function (aChar) {
|
return '\\x' + ('0' + aChar.charCodeAt(0).toString(16)).slice(-2);
|
||||||
return ('0' + aChar.charCodeAt(0).toString(16)).slice(-2);
|
})
|
||||||
})
|
.join('') + "'";
|
||||||
.join('')
|
this.copyContent(data);
|
||||||
.toUpperCase()
|
},
|
||||||
)
|
copyRaw() {
|
||||||
.then()
|
this.copyContent(Buffer.from(this.$props.content, 'base64').toString('hex'));
|
||||||
.catch(e => console.error('Failed to copy', e));
|
},
|
||||||
|
copyContent(data) {
|
||||||
|
const tempEl = document.createElement('textarea');
|
||||||
|
tempEl.value = data; // Chrome
|
||||||
|
tempEl.textContent = data; // Firefox
|
||||||
|
document.body.appendChild(tempEl);
|
||||||
|
tempEl.select();
|
||||||
|
const result = document.execCommand('copy');
|
||||||
|
document.body.removeChild(tempEl);
|
||||||
|
console.debug('Copy result is', result);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -78,5 +88,6 @@ export default {
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
top: -0.15em;
|
top: -0.15em;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
margin-left: 5px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user