()
| 803 | account.append(label, logout); |
| 804 | |
| 805 | const anchor = document.querySelector(".results-line") || |
| 806 | document.querySelector(".detail-actions"); |
| 807 | anchor?.insertAdjacentElement("afterend", account); |
| 808 | } |
| 809 | |
| 810 | async function loadVotes() { |
| 811 | if (voteControls.length === 0) return; |
| 812 | |
| 813 | try { |
| 814 | const response = await fetch(VOTE_API_URL, { |
| 815 | credentials: "same-origin", |
| 816 | headers: { Accept: "application/json" }, |
| 817 | }); |
| 818 | if (!response.ok) throw new Error("Voting unavailable"); |
| 819 | const body = await response.json(); |
| 820 | voteViewer = null; |
| 821 | viewerVotes = {}; |
| 822 | const sessionToken = readVoteSessionToken(); |
| 823 | if (sessionToken) { |
| 824 | try { |
| 825 | const sessionResponse = await fetch(`${LOOP_LIBRARY_PATH}/auth/session`, { |
| 826 | method: "POST", |
| 827 | credentials: "same-origin", |
| 828 | headers: { |
| 829 | Accept: "application/json", |
| 830 | "Content-Type": "application/json", |
| 831 | }, |
| 832 | body: JSON.stringify({ sessionToken }), |
| 833 | }); |
| 834 | if (!sessionResponse.ok) { |
| 835 | if (sessionResponse.status < 500) clearVoteSessionToken(); |
| 836 | } else { |
| 837 | const sessionBody = await sessionResponse.json(); |
| 838 | if (sessionBody.viewer) { |
| 839 | voteViewer = sessionBody.viewer; |
| 840 | viewerVotes = sessionBody.viewerVotes || {}; |
| 841 | } else { |
| 842 | clearVoteSessionToken(); |
| 843 | } |
| 844 | } |
| 845 | } catch { |
| 846 | // Public totals and the launch gate remain usable when restoring an |
| 847 | // existing session is temporarily unavailable. |
| 848 | } |
| 849 | } |
| 850 | voteControls.forEach((control) => { |
| 851 | const slug = control.dataset.loopSlug; |
| 852 | updateVoteControls( |
| 853 | control, |
| 854 | body.votes?.[slug], |
| 855 | viewerVotes[slug] || 0, |
| 856 | ); |
| 857 | }); |
| 858 | setVotingUiVisible(body.uiEnabled === true); |
| 859 | applySort(activeSort); |
| 860 | updateLibrary(); |
| 861 | if (body.uiEnabled === true) renderVoteAccount(); |
| 862 | } catch { |
no test coverage detected