(async () => { const SEARCH = 'themoniae'; const apolloClient = (() => { const entry = document.querySelector('[data-testid^="entry-"]'); const fk = Object.keys(entry).find(k => k.startsWith('__reactFiber')); let n = entry[fk]; while (n) { const ctx = n.memoizedProps?.value?.client ?? n.memoizedProps?.client; if (ctx?.cache) return ctx; n = n.return; } })(); const csrfToken = document.cookie.match(/csrf-token=([^;]+)/)?.[1] ?? ''; const fetchEntries = (from, limit) => fetch('/titanarum/public', { method: 'POST', headers: { 'content-type': 'application/json', 'x-csrf-token': csrfToken }, body: JSON.stringify({ operationName: 'Votes', variables: { slug: 'mediterranean-hues-2026-03', limit, from }, query: `query Votes($slug: String!, $from: Int, $limit: Int) { challengeEntriesForVoting(slug: $slug, from: $from, limit: $limit) { results { entries { id designId challengeId entryImage entryPlace validVotes isFavorite isSelected entryTitle entryDescription entryStatus entryState pdpUrl product image { L M S XS __typename } user { userId userName userImage __typename } __typename } __typename } __typename } }` }) }).then(r => r.json()); console.log('⏳ Fetching...'); const [res1, res2] = await Promise.all([fetchEntries(0, 1000), fetchEntries(1000, 1000)]); const allEntries = [ ...res1.data.challengeEntriesForVoting.results.entries, ...res2.data.challengeEntriesForVoting.results.entries ]; console.log(`✅ ${allEntries.length} entry`); const cacheSnapshot = apolloClient.cache.extract(); const toWrite = {}; const allRefs = allEntries.map(e => ({ __ref: `ChallengeEntryWithUserValues:${e.id}` })); allEntries.forEach(e => { const userKey = `BaseUser:{"userId":"${e.user.userId}"}`; toWrite[userKey] = { __typename: 'BaseUser', userId: e.user.userId, userName: e.user.userName, userImage: e.user.userImage }; toWrite[`ChallengeEntryWithUserValues:${e.id}`] = { __typename: 'ChallengeEntryWithUserValues', id: e.id, designId: e.designId, challengeId: e.challengeId, entryImage: e.entryImage, entryPlace: e.entryPlace, validVotes: e.validVotes, isFavorite: e.isFavorite, isSelected: e.isSelected, entryTitle: e.entryTitle, entryDescription: e.entryDescription, entryStatus: e.entryStatus, entryState: e.entryState, pdpUrl: e.pdpUrl, product: e.product, image: { __typename: 'DesignImage', L: e.image.L, M: e.image.M, S: e.image.S, XS: e.image.XS }, user: { __ref: userKey } }; }); const buildChallengeEntry = () => ({ __typename: 'ChallengeEntriesForVoting', info: { __typename: 'ChallengeEntriesVotingInfo', pagination: { __typename: 'Pagination', limit: allEntries.length, offset: 0, total: 1735 }, votingStats: { __ref: 'VotingStats:{}' } }, results: { __typename: 'ChallengeEntriesForVotingResults', entries: allRefs, promotedEntry: null, guestVoting: null } }); toWrite['ROOT_QUERY'] = { ...cacheSnapshot['ROOT_QUERY'], 'challengeEntriesForVoting({"from":null,"limit":84,"slug":"mediterranean-hues-2026-03"})': buildChallengeEntry(), 'challengeEntriesForVoting({"from":0,"limit":84,"slug":"mediterranean-hues-2026-03"})': buildChallengeEntry(), }; apolloClient.cache.restore({ ...cacheSnapshot, ...toWrite }); apolloClient.cache.broadcastWatches(); console.log('🎨 Cache aggiornata!'); await new Promise(r => setTimeout(r, 1000)); const handleGuestModal = async () => { await new Promise(r => setTimeout(r, 600)); const guestBtn = document.querySelector('[data-testid="voteAsGuest"]'); if (guestBtn) { console.log('👤 Clicco "Vote as Guest User"'); guestBtn.click(); await new Promise(r => setTimeout(r, 800)); } }; const clickVote = async (el) => { const title = el.querySelector('[data-testid="entryTitle"]')?.textContent; const artist = el.querySelector('[data-testid="artistName"]')?.textContent; const btn = el.querySelector('[data-testid="voteButton"]'); if (!btn) { console.warn('❌ Bottone non trovato'); return; } if (btn.classList.contains('MuiButton-contained')) { console.log(`✅ Già selezionato: "${title}" by ${artist}`); return; } el.style.outline = '3px solid red'; el.scrollIntoView({ behavior: 'smooth', block: 'center' }); await new Promise(r => setTimeout(r, 800)); btn.click(); console.log(`🗳️ Votato: "${title}" by ${artist}`); await handleGuestModal(); }; const allDomEntries = [...document.querySelectorAll('[data-testid^="entry-"]')]; const moniaIdx = allDomEntries.findIndex(el => el.querySelector('[data-testid="entryTitle"]')?.textContent.toLowerCase().includes(SEARCH.toLowerCase()) || el.querySelector('[data-testid="artistName"]')?.textContent.toLowerCase().includes(SEARCH.toLowerCase()) ); if (moniaIdx === -1) { console.warn(`❌ "${SEARCH}" non trovata`); } else { console.log(`🎯 Trovata all'indice ${moniaIdx}`); await clickVote(allDomEntries[moniaIdx]); for (let i = 1; i <= 2; i++) { const next = allDomEntries[moniaIdx + i]; if (next) await clickVote(next); } // Scrolla a Submit — clicca tu! await new Promise(r => setTimeout(r, 800)); const submitBtn = document.querySelector('[data-testid="submitVotes"]'); if (submitBtn) { submitBtn.scrollIntoView({ behavior: 'smooth', block: 'center' }); console.log('👆 Pronto — clicca Submit quando vuoi!'); } else { console.warn('⚠️ Submit non trovato'); } } })();