fix copy to clipboard in binary
This commit is contained in:
parent
475ff8f7e2
commit
04c9c20732
@ -1,5 +1,5 @@
|
|||||||
body {
|
body {
|
||||||
background-color: #6497b1;
|
background-color: #ac7489;
|
||||||
font-family: "Courier Prime", monospace;
|
font-family: "Courier Prime", monospace;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
@ -12,10 +12,11 @@ body {
|
|||||||
overflow: auto;
|
overflow: auto;
|
||||||
width: 75vw;
|
width: 75vw;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
|
padding: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.submit {
|
.submit {
|
||||||
background-color: #03396c;
|
background-color: #883d3d;
|
||||||
border: 2px black solid;
|
border: 2px black solid;
|
||||||
/* width: 25vw; */
|
/* width: 25vw; */
|
||||||
height: 100px;
|
height: 100px;
|
||||||
@ -32,6 +33,8 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#out {
|
#out {
|
||||||
|
display: flex;
|
||||||
|
align-self: center;
|
||||||
border: 4px black solid;
|
border: 4px black solid;
|
||||||
width: 75vw;
|
width: 75vw;
|
||||||
height: 5rem;
|
height: 5rem;
|
||||||
|
|||||||
102
binary/binary.js
102
binary/binary.js
@ -1,61 +1,77 @@
|
|||||||
function out0() {
|
function out0() {
|
||||||
document.getElementById("out").innerHTML = "";
|
document.getElementById("out").innerHTML = "";
|
||||||
if (document.getElementById("text_binary").checked == true) out();
|
if (document.getElementById("text_binary").checked == true) out();
|
||||||
else if (document.getElementById("binary_text").checked == true) out1();
|
else if (document.getElementById("binary_text").checked == true) out1();
|
||||||
}
|
}
|
||||||
|
|
||||||
function out() {
|
function out() {
|
||||||
console.log("out");
|
console.log("out");
|
||||||
document.getElementById("out").innerHTML = "";
|
document.getElementById("out").innerHTML = "";
|
||||||
var binary_out = "";
|
var binary_out = "";
|
||||||
document.getElementById("input").innerHTML.replace(/ /g, '');
|
document.getElementById("input").innerHTML.replace(/ /g, "");
|
||||||
var input = document.getElementById("input").textContent;
|
var input = document.getElementById("input").textContent;
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (var i = 0; i < input.length; i++) {
|
||||||
var z = input.charCodeAt(i).toString(2);
|
var z = input.charCodeAt(i).toString(2);
|
||||||
if (input.charAt(i) == " ") {
|
if (input.charAt(i) == " ") {
|
||||||
binary_out += "00100000 ";
|
binary_out += "00100000 ";
|
||||||
} else {
|
} else {
|
||||||
while (z.length < 8) {
|
while (z.length < 8) {
|
||||||
z = "0" + z;
|
z = "0" + z;
|
||||||
}
|
}
|
||||||
binary_out += z;
|
binary_out += z;
|
||||||
binary_out += " ";
|
binary_out += " ";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
document.getElementById("out").innerHTML = binary_out;
|
}
|
||||||
|
document.getElementById("out").innerHTML = binary_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
function out1() {
|
function out1() {
|
||||||
console.log("out1");
|
console.log("out1");
|
||||||
document.getElementById("out").innerHTML = "";
|
document.getElementById("out").innerHTML = "";
|
||||||
var text_out = "";
|
var text_out = "";
|
||||||
var input = document.getElementById("input").textContent.replace(/ /g, "");
|
var input = document.getElementById("input").textContent.replace(/ /g, "");
|
||||||
input = input.replace(/ /gi, "");
|
input = input.replace(/ /gi, "");
|
||||||
for (var i = 0; i < input.length; i = i + 8) {
|
for (var i = 0; i < input.length; i = i + 8) {
|
||||||
var z = '';
|
var z = "";
|
||||||
var z = input.substr(i, 8);
|
var z = input.substr(i, 8);
|
||||||
text_out += String.fromCharCode(parseInt(z, 2)) + "";
|
text_out += String.fromCharCode(parseInt(z, 2)) + "";
|
||||||
}
|
}
|
||||||
document.getElementById("out").textContent = String(text_out);
|
document.getElementById("out").textContent = String(text_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
function copy0() {
|
function copy0() {
|
||||||
document.getElementById("out").value.select();
|
document.getElementById("out").value.select();
|
||||||
}
|
}
|
||||||
|
|
||||||
function copy() {
|
function copy() {
|
||||||
if (document.selection) {
|
if (document.selection) {
|
||||||
var div = document.body.createTextRange();
|
var div = document.body.createTextRange();
|
||||||
div.moveToElementText(document.getElementById("out"));
|
div.moveToElementText(document.getElementById("out"));
|
||||||
div.select();
|
div.select();
|
||||||
} else {
|
} else {
|
||||||
var div = document.createRange();
|
var div = document.createRange();
|
||||||
div.setStartBefore(document.getElementById("out"));
|
div.setStartBefore(document.getElementById("out"));
|
||||||
div.setEndAfter(document.getElementById("out"));
|
div.setEndAfter(document.getElementById("out"));
|
||||||
window.getSelection().addRange(div);
|
window.getSelection().addRange(div);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function clear1() {
|
function clear1() {
|
||||||
document.getElementById("input").textContent = "";
|
document.getElementById("input").textContent = "";
|
||||||
|
}
|
||||||
|
let copyText = document.getElementById("out");
|
||||||
|
function copyOut() {
|
||||||
|
// Get the text field
|
||||||
|
copyText = document.getElementById("out");
|
||||||
|
// focus text feild
|
||||||
|
copyText.focus();
|
||||||
|
// Select the text field
|
||||||
|
copyText.select();
|
||||||
|
copyText.setSelectionRange(0, 99999); // For mobile devices
|
||||||
|
|
||||||
|
// Copy the text inside the text field
|
||||||
|
navigator.clipboard.writeText(copyText.value);
|
||||||
|
|
||||||
|
// Alert the copied text
|
||||||
|
alert("Copied the text: " + copyText.value);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,8 +9,8 @@
|
|||||||
<link href="https://fonts.googleapis.com/css2?family=Courier+Prime&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Courier+Prime&display=swap" rel="stylesheet">
|
||||||
<title>Binary</title>
|
<title>Binary</title>
|
||||||
<link rel="stylesheet" type="text/css" href="/menu/menu.css" />
|
<link rel="stylesheet" type="text/css" href="/menu/menu.css" />
|
||||||
<link rel="icon" type="image/ico" href="../binary.ico">
|
<link rel="icon" type="image/ico" href="/binary/binary.ico">
|
||||||
<link rel="stylesheet" type="text/css" href="binary.css" />
|
<link rel="stylesheet" type="text/css" href="/binary/binary.css" />
|
||||||
<script defer data-domain="chrisedwards.tech" src="https://metric1.chrisedwards.tech/js/plausible.js"></script>
|
<script defer data-domain="chrisedwards.tech" src="https://metric1.chrisedwards.tech/js/plausible.js"></script>
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
|
||||||
|
|
||||||
@ -38,8 +38,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div id="out" onclick="copy()">
|
<textarea id="out" onclick="copyOut()">
|
||||||
<div>
|
</textarea>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user