code copy paste
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- Replace agate with your theme - find themes at https://highlightjs.org/demo -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/tomorrow-night-bright.min.css">
<!-- For icons -->
<script type="module" src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.esm.js"></script>
<script nomodule src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.js"></script>
<style>
.code-block {
position: relative;
width: 80%;
height: auto;
margin: auto;
font-size: 1.2rem;
overflow: hidden;
}
.code-block pre {
border-radius: 10px;
background-color: #686de0;
}
.code-block .copy-btn {
position: absolute;
padding: 10px 20px;
background-color: whitesmoke;
display: flex;
align-items: center;
justify-content: center;
border-radius: 5px;
right: 20px;
top: 55px;
cursor: pointer;
transition: 0.5s;
font-weight: 600;
}
.code-block .copy-btn:hover {
transform: scale(1.1);
}
.green {
color: #6ab04c;
}
.black {
color: #000;
}
</style>
</head>
<body>
<h1>HTML First Code</h1>
<!-- Only add code inside the code-block -->
<div class="code-block">
<div class="copy-btn">
<ion-icon name="copy-outline"></ion-icon>
</div>
<!-- Change your language using this -->
<pre>
<code class="language-html">
if your code in html first parse your code
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
</code>
</pre>
</div>
<!-- Only add code inside the code-block -->
<div class="code-block">
<div class="copy-btn">
<ion-icon name="copy-outline"></ion-icon>
</div>
<!-- Change your language using this -->
<pre>
<code class="language-html">
<!DOCTYPE html>
<html>
<head>
<title>Hello World 2</title>
</head>
<body>
<h1>Hello, World! 2</h1>
</body>
</html>
</code>
</pre>
</div>
<!-- JS -->
<script>
let htmlData = [];
function storeData() {
let copyBtn = document.querySelectorAll(".copy-btn");
Array.from(copyBtn).forEach((btn) => {
let icon = btn.querySelector("ion-icon");
let codeBox = btn.parentElement.querySelector("code")
let codeBoxHtml = codeBox.innerHTML;
let storeData = codeBoxHtml.replaceAll(">",">").replaceAll("<","<")
htmlData.push(storeData)
})
}
storeData()
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
hljs.highlightAll();
});
let copyBtn = document.querySelectorAll(".copy-btn");
function copyClicpbaord(index) {
navigator.clipboard.writeText(htmlData[index])
}
function handleBtnClick(btn, element,index) {
let icon = btn.querySelector("ion-icon");
copyClicpbaord(index)
icon.name = "checkmark-circle-outline";
icon.classList.remove("block");
icon.classList.add("green");
if (icon.name === "checkmark-circle-outline") {
setTimeout(() => {
icon.name = "copy-outline";
icon.classList.remove("green");
icon.classList.add("black");
}, 2000);
}
}
Array.from(copyBtn).forEach((btn,index) => {
btn.addEventListener("click", (e) => { handleBtnClick(btn, e,index) });
})
</script>
</body>
</html>
Comments
Post a Comment