Advertisement
MeckeOfficial

Twitter Giveaway Picker

May 9th, 2024 (edited)
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. javascript: (function() {
  2.     let hrefList = [];
  3.     let scrollAttempts = 0;
  4.  
  5.     function processSections() {
  6.         const sections = document.getElementsByTagName('section');
  7.         for (let i = 0; i < sections.length; i++) {
  8.             const section = sections[i];
  9.             if (section.hasAttribute('aria-labelledby')) {
  10.                 const ariaLabelledById = section.getAttribute('aria-labelledby');
  11.                 if (ariaLabelledById.startsWith('accessible-list')) {
  12.                     const h1Elements = section.getElementsByTagName('h1');
  13.                     for (let j = 0; j < h1Elements.length; j++) {
  14.                         const h1Element = h1Elements[j];
  15.                         if (h1Element.getAttribute('role') === 'heading' && (h1Element.textContent.trim() === 'Reposts' || h1Element.textContent.trim() === 'Likes' || h1Element.textContent.trim() === 'Quotes')) {
  16.                             const cellInnerDivs = section.querySelectorAll('[data-testid="cellInnerDiv"]');
  17.                             cellInnerDivs.forEach(cellInnerDiv => {
  18.                                 const hrefRegex = /href="([^"]*)"/;
  19.                                 const match = cellInnerDiv.innerHTML.match(hrefRegex);
  20.                                 if (match && match[1]) {
  21.                                     const href = match[1];
  22.                                     if (!hrefList.includes(href)) {
  23.                                         hrefList.push(href);
  24.                                         updateHrefsCountDisplay();
  25.                                         console.log("New href added:", href);
  26.                                     }
  27.                                 }
  28.                             });
  29.                             break;
  30.                         }
  31.                     }
  32.                 }
  33.             }
  34.         }
  35.     }
  36.  
  37.     function pickWinner() {
  38.         if (hrefList.length > 0) {
  39.             const randomIndex = Math.floor(Math.random() * hrefList.length);
  40.             const selectedHref = hrefList[randomIndex];
  41.             winnerButton.textContent = selectedHref;
  42.             winnerButton.href = selectedHref;
  43.             hrefList.splice(randomIndex, 1);
  44.             updateHrefsCountDisplay();
  45.         } else {
  46.             winnerButton.textContent = "No entries available";
  47.             winnerButton.removeAttribute('href');
  48.         }
  49.     }
  50.  
  51.     function handlePickWinner() {
  52.         hrefList = [];
  53.         processSections();
  54.         const scrollInterval = setInterval(function() {
  55.             window.scrollBy(0, window.innerHeight);
  56.             scrollAttempts++;
  57.             if (scrollAttempts >= 3) {
  58.                 scrollAttempts = 0;
  59.                 const prevLength = hrefList.length;
  60.                 processSections();
  61.                 if (hrefList.length === prevLength) {
  62.                     clearInterval(scrollInterval);
  63.                     console.log("Reached end. List of hrefs:", hrefList);
  64.                     pickWinner();
  65.                 }
  66.             }
  67.         }, 1000);
  68.     }
  69.  
  70.     function handleReroll() {
  71.         pickWinner();
  72.     }
  73.  
  74.     function updateHrefsCountDisplay() {
  75.         hrefCountDisplay.textContent = `Total hrefs: ${hrefList.length}`;
  76.     }
  77.     const pickWinnerButton = document.createElement('button');
  78.     pickWinnerButton.textContent = 'Pick a Winner';
  79.     pickWinnerButton.addEventListener('click', handlePickWinner);
  80.     document.body.appendChild(pickWinnerButton);
  81.     pickWinnerButton.style.position = 'fixed';
  82.     pickWinnerButton.style.top = '10px';
  83.     pickWinnerButton.style.left = '10px';
  84.     pickWinnerButton.style.backgroundColor = 'green';
  85.     pickWinnerButton.style.color = 'white';
  86.     pickWinnerButton.style.padding = '10px 20px';
  87.     pickWinnerButton.style.border = 'none';
  88.     pickWinnerButton.style.borderRadius = '5px';
  89.     pickWinnerButton.style.cursor = 'pointer';
  90.     const rerollButton = document.createElement('button');
  91.     rerollButton.textContent = 'Reroll';
  92.     rerollButton.addEventListener('click', handleReroll);
  93.     document.body.appendChild(rerollButton);
  94.     rerollButton.style.position = 'fixed';
  95.     rerollButton.style.top = '10px';
  96.     rerollButton.style.left = '150px';
  97.     rerollButton.style.backgroundColor = 'blue';
  98.     rerollButton.style.color = 'white';
  99.     rerollButton.style.padding = '10px 20px';
  100.     rerollButton.style.border = 'none';
  101.     rerollButton.style.borderRadius = '5px';
  102.     rerollButton.style.cursor = 'pointer';
  103.     const winnerButton = document.createElement('a');
  104.     winnerButton.textContent = '- None -';
  105.     document.body.appendChild(winnerButton);
  106.     winnerButton.style.position = 'fixed';
  107.     winnerButton.style.top = '50px';
  108.     winnerButton.style.left = '10px';
  109.     winnerButton.style.backgroundColor = 'blue';
  110.     winnerButton.style.color = 'white';
  111.     winnerButton.style.padding = '10px 20px';
  112.     winnerButton.style.border = 'none';
  113.     winnerButton.style.borderRadius = '5px';
  114.     winnerButton.style.cursor = 'pointer';
  115.     const hrefCountDisplay = document.createElement('span');
  116.     hrefCountDisplay.textContent = `Total hrefs: ${hrefList.length}`;
  117.     document.body.appendChild(hrefCountDisplay);
  118.     hrefCountDisplay.style.position = 'fixed';
  119.     hrefCountDisplay.style.top = '90px';
  120.     hrefCountDisplay.style.left = '10px';
  121.     hrefCountDisplay.style.color = 'black';
  122. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement