ftp21

Untitled

Mar 17th, 2026 (edited)
7,011
0
Never
3
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (async () => {
  2.  
  3. const SEARCH = 'themoniae';
  4.  
  5. const apolloClient = (() => {
  6.     const entry = document.querySelector('[data-testid^="entry-"]');
  7.     const fk = Object.keys(entry).find(k => k.startsWith('__reactFiber'));
  8.     let n = entry[fk];
  9.     while (n) {
  10.         const ctx = n.memoizedProps?.value?.client ?? n.memoizedProps?.client;
  11.         if (ctx?.cache) return ctx;
  12.         n = n.return;
  13.     }
  14. })();
  15.  
  16. const csrfToken = document.cookie.match(/csrf-token=([^;]+)/)?.[1] ?? '';
  17. const fetchEntries = (from, limit) => fetch('/titanarum/public', {
  18.     method: 'POST',
  19.     headers: { 'content-type': 'application/json', 'x-csrf-token': csrfToken },
  20.     body: JSON.stringify({
  21.         operationName: 'Votes',
  22.         variables: { slug: 'mediterranean-hues-2026-03', limit, from },
  23.         query: `query Votes($slug: String!, $from: Int, $limit: Int) {
  24.             challengeEntriesForVoting(slug: $slug, from: $from, limit: $limit) {
  25.                 results {
  26.                     entries {
  27.                         id designId challengeId entryImage entryPlace validVotes
  28.                         isFavorite isSelected entryTitle entryDescription
  29.                         entryStatus entryState pdpUrl product
  30.                         image { L M S XS __typename }
  31.                         user { userId userName userImage __typename }
  32.                         __typename
  33.                     }
  34.                     __typename
  35.                 }
  36.                 __typename
  37.             }
  38.         }`
  39.     })
  40. }).then(r => r.json());
  41.  
  42. console.log('⏳ Fetching...');
  43. const [res1, res2] = await Promise.all([fetchEntries(0, 1000), fetchEntries(1000, 1000)]);
  44. const allEntries = [
  45.     ...res1.data.challengeEntriesForVoting.results.entries,
  46.     ...res2.data.challengeEntriesForVoting.results.entries
  47. ];
  48. console.log(`✅ ${allEntries.length} entry`);
  49.  
  50. const cacheSnapshot = apolloClient.cache.extract();
  51. const toWrite = {};
  52. const allRefs = allEntries.map(e => ({ __ref: `ChallengeEntryWithUserValues:${e.id}` }));
  53.  
  54. allEntries.forEach(e => {
  55.     const userKey = `BaseUser:{"userId":"${e.user.userId}"}`;
  56.     toWrite[userKey] = { __typename: 'BaseUser', userId: e.user.userId, userName: e.user.userName, userImage: e.user.userImage };
  57.     toWrite[`ChallengeEntryWithUserValues:${e.id}`] = {
  58.         __typename: 'ChallengeEntryWithUserValues',
  59.         id: e.id, designId: e.designId, challengeId: e.challengeId,
  60.         entryImage: e.entryImage, entryPlace: e.entryPlace, validVotes: e.validVotes,
  61.         isFavorite: e.isFavorite, isSelected: e.isSelected, entryTitle: e.entryTitle,
  62.         entryDescription: e.entryDescription, entryStatus: e.entryStatus,
  63.         entryState: e.entryState, pdpUrl: e.pdpUrl, product: e.product,
  64.         image: { __typename: 'DesignImage', L: e.image.L, M: e.image.M, S: e.image.S, XS: e.image.XS },
  65.         user: { __ref: userKey }
  66.     };
  67. });
  68.  
  69. const buildChallengeEntry = () => ({
  70.     __typename: 'ChallengeEntriesForVoting',
  71.     info: {
  72.         __typename: 'ChallengeEntriesVotingInfo',
  73.         pagination: { __typename: 'Pagination', limit: allEntries.length, offset: 0, total: 1735 },
  74.         votingStats: { __ref: 'VotingStats:{}' }
  75.     },
  76.     results: {
  77.         __typename: 'ChallengeEntriesForVotingResults',
  78.         entries: allRefs, promotedEntry: null, guestVoting: null
  79.     }
  80. });
  81.  
  82. toWrite['ROOT_QUERY'] = {
  83.     ...cacheSnapshot['ROOT_QUERY'],
  84.     'challengeEntriesForVoting({"from":null,"limit":84,"slug":"mediterranean-hues-2026-03"})': buildChallengeEntry(),
  85.     'challengeEntriesForVoting({"from":0,"limit":84,"slug":"mediterranean-hues-2026-03"})': buildChallengeEntry(),
  86. };
  87.  
  88. apolloClient.cache.restore({ ...cacheSnapshot, ...toWrite });
  89. apolloClient.cache.broadcastWatches();
  90. console.log('🎨 Cache aggiornata!');
  91. await new Promise(r => setTimeout(r, 1000));
  92.  
  93. const handleGuestModal = async () => {
  94.     await new Promise(r => setTimeout(r, 600));
  95.     const guestBtn = document.querySelector('[data-testid="voteAsGuest"]');
  96.     if (guestBtn) {
  97.         console.log('👤 Clicco "Vote as Guest User"');
  98.         guestBtn.click();
  99.         await new Promise(r => setTimeout(r, 800));
  100.     }
  101. };
  102.  
  103. const clickVote = async (el) => {
  104.     const title = el.querySelector('[data-testid="entryTitle"]')?.textContent;
  105.     const artist = el.querySelector('[data-testid="artistName"]')?.textContent;
  106.     const btn = el.querySelector('[data-testid="voteButton"]');
  107.     if (!btn) { console.warn('❌ Bottone non trovato'); return; }
  108.     if (btn.classList.contains('MuiButton-contained')) {
  109.         console.log(`✅ Già selezionato: "${title}" by ${artist}`);
  110.         return;
  111.     }
  112.     el.style.outline = '3px solid red';
  113.     el.scrollIntoView({ behavior: 'smooth', block: 'center' });
  114.     await new Promise(r => setTimeout(r, 800));
  115.     btn.click();
  116.     console.log(`🗳️ Votato: "${title}" by ${artist}`);
  117.     await handleGuestModal();
  118. };
  119.  
  120. const allDomEntries = [...document.querySelectorAll('[data-testid^="entry-"]')];
  121. const moniaIdx = allDomEntries.findIndex(el =>
  122.     el.querySelector('[data-testid="entryTitle"]')?.textContent.toLowerCase().includes(SEARCH.toLowerCase())
  123.     || el.querySelector('[data-testid="artistName"]')?.textContent.toLowerCase().includes(SEARCH.toLowerCase())
  124. );
  125.  
  126. if (moniaIdx === -1) {
  127.     console.warn(`❌ "${SEARCH}" non trovata`);
  128. } else {
  129.     console.log(`🎯 Trovata all'indice ${moniaIdx}`);
  130.    await clickVote(allDomEntries[moniaIdx]);
  131.    for (let i = 1; i <= 2; i++) {
  132.        const next = allDomEntries[moniaIdx + i];
  133.        if (next) await clickVote(next);
  134.    }
  135.  
  136.    // Scrolla a Submit — clicca tu!
  137.    await new Promise(r => setTimeout(r, 800));
  138.    const submitBtn = document.querySelector('[data-testid="submitVotes"]');
  139.    if (submitBtn) {
  140.        submitBtn.scrollIntoView({ behavior: 'smooth', block: 'center' });
  141.        console.log('👆 Pronto — clicca Submit quando vuoi!');
  142.    } else {
  143.        console.warn('⚠️ Submit non trovato');
  144.    }
  145. }
  146.  
  147. })();
  148.  
Advertisement