1import {Modal} from '../../ui/modal.js' 2import {firemsg} from '../../ui/firemsg.js' 3import {L} from '../../ui/utils.js' 4 5const modal = document.getElementById('poll-modal') 6const body = modal.querySelector('.modal-body') 7 8document.body.addEventListener('click', async e => { 9 const button = e.target.closest('[data-action]') 10 if (!button) return 11 const poll = button.closest('.as-poll') 12 if (!poll) return 13 14 const formData = new FormData() 15 formData.set('pollid', poll.dataset.id) 16 formData.set('voteid', button.closest('.as-poll-vote').dataset.id) 17 18 switch (button.dataset.action) { 19 case 'vote': 20 formData.set('getusers', '0') 21 const text = button.parentElement.previousElementSibling.textContent 22 if (!confirm(L(`ÐодÑвеÑдиÑе Ð³Ð¾Ð»Ð¾Ñ Ð·Ð° "${text}"`, `Confirm your vote for "${text}"`))) return 23 const request = await fetch('/resource/rating-and-polls/do', {method: 'post', body: formData}) 24 const response = await request.json() 25 26 if (response.error) { 27 firemsg(`ÐÑибка! ${response.error}`) 28 return 29 } 30 31 if (response.html) poll.outerHTML = response.html 32 break 33 34 case 'explain': 35 formData.set('getusers', '1') 36 Modal.open(async () => { 37 const request = await fetch('/resource/rating-and-polls/do', {method: 'post', body: formData}) 38 /** @type {{error?:string,userbits?:string}} */ 39 const response = await request.json() 40 if (response.error) { 41 body.innerHTML = response.error 42 return modal 43 } 44 45 if (response.userbits) { 46 body.innerHTML = response.userbits 47 const text = button.previousElementSibling.textContent 48 body.insertAdjacentHTML('afterbegin', `<div class="well well-small">${text}</div>`) 49 return modal 50 } 51 52 }, () => body.textContent = '') 53 break 54 } 55})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.