`
].join('\n');
btnYes.onclick = () => {
let hE = document.querySelector('.hE');
if(hE) stage.removeChild(hE);
if(btnYes.value === '1') {
str = text.value;
if(!str) return;
str = str.replaceAll('<', '<');
str = str.replaceAll('>', '>')
text.value = '\n\n' + _js.replaceAll('<', '<').replaceAll('>', '>');
let sdiv = document.createElement('div');
sdiv.className = 'hE';
sdiv.dataset.prev = '1';
sdiv.innerHTML = '' + str + '
';
stage.appendChild(sdiv);
//hERender();
helight.hl(sdiv,spre);
btnCopy.style.display = 'inline-block';
btnYes.value = '0';
}else{
text.value = '';
btnYes.value = '1';
btnCopy.style.display = 'none';
}
btnYes.innerText = ['重置到初始状态','生成helight代码'][+btnYes.value];
};
btnCopy.onclick = () => {
let copiedStr = text.value;
if(navigator.clipboard) {
navigator.clipboard
.writeText(copiedStr)
.then (() => {
showMsg(msgBox,'成功复制到剪切板!');
})
.catch(err => {
console.log(err);
});
}else{
text.focus;
text.select();
document.execCommand('copy');
showMsg(msgBox,'成功复制到剪切板啦!');
}
};
text.onkeydown = (e) => {
if(e.key === 'Tab') {
e.preventDefault();
const spaces = ' ';
let currentValue = text.value;
const startPos = text.selectionStart;
const endPos = text.selectionEnd;
text.value = currentValue.slice(0, startPos) + spaces + currentValue.slice(endPos);
text.selectionStart = text.selectionEnd = startPos + spaces.length;
}
};
const showMsg = (ele,msg) => {
ele.value = msg;
btnCopy.style.display = 'none';
setTimeout(() => {
ele.value = '';
}, 2000);
};