double click elements to paste
This commit is contained in:
parent
6035188380
commit
6018b134d0
3 changed files with 47 additions and 10 deletions
10
index.css
10
index.css
|
@ -52,7 +52,8 @@ body {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
button, button a {
|
button,
|
||||||
|
button a {
|
||||||
color: #fff;
|
color: #fff;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
@ -61,7 +62,7 @@ button a {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 2rem;
|
height: 2rem;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
line-height:2rem;
|
line-height: 2rem;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
@ -76,6 +77,10 @@ button a {
|
||||||
padding: 0.5rem 1rem;
|
padding: 0.5rem 1rem;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
#messages>li>li:hover {
|
||||||
|
font-weight: bolder;
|
||||||
|
}
|
||||||
|
|
||||||
#messages>li>li {
|
#messages>li>li {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
line-height: 1em;
|
line-height: 1em;
|
||||||
|
@ -86,7 +91,6 @@ button a {
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#messages>li>li>img {
|
#messages>li>li>img {
|
||||||
height: 1.1em;
|
height: 1.1em;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<ul id="messages"></ul>
|
<ul id="messages"></ul>
|
||||||
<form id="form" action="">
|
<form id="form" action="">
|
||||||
<div class='inner-form'>
|
<div class='inner-form'>
|
||||||
<input id="input" autocomplete="off" />
|
<input placeholder="Double click text to paste" id="input" autocomplete="off" />
|
||||||
</div>
|
</div>
|
||||||
<div class='inner-form'>
|
<div class='inner-form'>
|
||||||
<button class='send'><a href='#'>Send</a></button>
|
<button class='send'><a href='#'>Send</a></button>
|
||||||
|
|
45
index.js
45
index.js
|
@ -4,6 +4,29 @@ var form = document.getElementById('form');
|
||||||
var input = document.getElementById('input');
|
var input = document.getElementById('input');
|
||||||
const server = new URLSearchParams(document.location.search).get('server') || '/';
|
const server = new URLSearchParams(document.location.search).get('server') || '/';
|
||||||
|
|
||||||
|
async function clickLi(e) {
|
||||||
|
let t = e.target;
|
||||||
|
if (t.tagName.toLowerCase() != 'li') return;
|
||||||
|
if (t.parentNode.tagName.toLowerCase() != 'li') return;
|
||||||
|
if (!t.querySelector('img')) return;
|
||||||
|
|
||||||
|
let content = t.textContent;
|
||||||
|
if (content == '') return;
|
||||||
|
|
||||||
|
let delimiter = ';';
|
||||||
|
if (input.value[0] == '/') delimiter = ' ';
|
||||||
|
if (input.value.indexOf(',') != -1) delimiter = ',';
|
||||||
|
if (input.value.indexOf(';') != -1) delimiter = ';';
|
||||||
|
if (input.value.indexOf('+') != -1) delimiter = '+';
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
if (input.value == '') {
|
||||||
|
input.value = `${e.target.textContent}`;
|
||||||
|
} else {
|
||||||
|
input.value = `${input.value}${delimiter}${e.target.textContent}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function goPage(count) {
|
async function goPage(count) {
|
||||||
let counter = input.value.match(/[^\s]+$/g);
|
let counter = input.value.match(/[^\s]+$/g);
|
||||||
if (!counter) return false;
|
if (!counter) return false;
|
||||||
|
@ -21,9 +44,9 @@ async function addMsg(msg) {
|
||||||
var item = document.createElement('li');
|
var item = document.createElement('li');
|
||||||
item.textContent = line;
|
item.textContent = line;
|
||||||
|
|
||||||
if (line[0] == '-' ||line[0] == '<' ) {
|
if (line[0] == '-' || line[0] == '<') {
|
||||||
let img = new Image();
|
let img = new Image();
|
||||||
if (line[0] == '<' ) {
|
if (line[0] == '<') {
|
||||||
item.textContent = line.slice(3);
|
item.textContent = line.slice(3);
|
||||||
img.src = `arrows/left.svg`;
|
img.src = `arrows/left.svg`;
|
||||||
} else if (line[1] == '>') {
|
} else if (line[1] == '>') {
|
||||||
|
@ -37,6 +60,8 @@ async function addMsg(msg) {
|
||||||
item.style.fontStyle = 'italic';
|
item.style.fontStyle = 'italic';
|
||||||
}
|
}
|
||||||
wrap.appendChild(item);
|
wrap.appendChild(item);
|
||||||
|
|
||||||
|
item.title = 'Double click to copy';
|
||||||
}
|
}
|
||||||
messages.appendChild(wrap);
|
messages.appendChild(wrap);
|
||||||
window.scrollTo(0, messages.offsetHeight);
|
window.scrollTo(0, messages.offsetHeight);
|
||||||
|
@ -61,6 +86,10 @@ async function main(e) {
|
||||||
addMsg(input.value)
|
addMsg(input.value)
|
||||||
addMsg(msg)
|
addMsg(msg)
|
||||||
|
|
||||||
|
if (input.value[0] != '/') {
|
||||||
|
input.value = '';
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,12 +98,16 @@ form.addEventListener('submit', main);
|
||||||
document.querySelector('.send').addEventListener('click', main);
|
document.querySelector('.send').addEventListener('click', main);
|
||||||
document.querySelector('.prev').addEventListener('click', (e) => { e.preventDefault(); return goPage(1) });
|
document.querySelector('.prev').addEventListener('click', (e) => { e.preventDefault(); return goPage(1) });
|
||||||
document.querySelector('.next').addEventListener('click', (e) => { e.preventDefault(); return goPage(-1) });
|
document.querySelector('.next').addEventListener('click', (e) => { e.preventDefault(); return goPage(-1) });
|
||||||
|
document.querySelector('#messages').addEventListener('dblclick', clickLi);
|
||||||
|
|
||||||
|
input.value = '/inv 1';
|
||||||
input.value = '/help 1';
|
|
||||||
goPage(0);
|
goPage(0);
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
input.value = '/inv 1';
|
input.value = '/help 1';
|
||||||
goPage(0);
|
goPage(0);
|
||||||
}, 500)
|
}, 500)
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
input.value = '';
|
||||||
|
}, 1000)
|
Loading…
Add table
Add a link
Reference in a new issue