+ cb.addEventListener('click', (function(cb) {
+ return function() {
+ cb.style.display = 'none'
+ const spin = document.createElement('div')
+ spin.appendChild(document.createTextNode('⏳'))
+ cb.parentElement.insertBefore(spin, cb)
+
+ const req = new XMLHttpRequest()
+ req.addEventListener('load', function(e) {
+ cb.parentElement.removeChild(cb.previousElementSibling)
+ if (req.status == 200) {
+ cb.style.display = ''
+ const delta = cb.checked ? 1 : -1
+ const count_td = cb.parentElement.previousElementSibling
+ count_td.textContent = parseInt(count_td.textContent) + delta
+ } else {
+ cb.parentElement.insertBefore(document.createTextNode('❗'), cb)
+ }
+ })
+ req.open('PUT', window.location.href)
+ req.send((cb.checked ? 1 : 0) + ' ' + cb.parentElement.nextElementSibling.innerHTML)
+ }
+ })(cb))