<span class="badge bg-danger" onclick="changeBadge(150, 200)" style="cursor: pointer;">150</span>
<span class="badge bg-danger" onclick="changeBadge(250, 255)" style="cursor: pointer;">250</span>
<span class="badge bg-danger" onclick="changeBadge(350, 235)" style="cursor: pointer;">350</span>
<span class="badge bg-danger" onclick="changeBadge(450, 225)" style="cursor: pointer;">450</span>
<script>
const changeBadge = (oldContent, newContent) => {
const badge = event.target
if (badge.classList.contains('bg-danger')) {
badge.classList.add('bg-success')
badge.classList.remove('bg-danger')
badge.innerHTML = newContent
} else {
badge.classList.remove('bg-success')
badge.classList.add('bg-danger')
badge.innerHTML = oldContent
}
}
</script>
if (typeof(json.dialog) == 'object') {
const _dialog = json.dialog.reduce((acc,cur,i,a)=>{
const index = acc.findIndex(item => item.date === cur.date)
if( index !== -1 ){
acc[index].message.push({text: cur.text, time: cur.time})
}else{
cur.message = []
cur.message.push({text: cur.text, time: cur.time})
acc.push(cur)
}
return acc
},[])
$('div.dialog').html(_dialog.map(item => {
let div = `<div>${item.date}</div>`
item.message.forEach(_item => {
div += `<div><span name="text">${_item.text}</span><span name="time">${_item.time}</span></div>`
})
return div;
}).join(''));
}