Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- javascript: (function() {
- let hrefList = [];
- let scrollAttempts = 0;
- function processSections() {
- const sections = document.getElementsByTagName('section');
- for (let i = 0; i < sections.length; i++) {
- const section = sections[i];
- if (section.hasAttribute('aria-labelledby')) {
- const ariaLabelledById = section.getAttribute('aria-labelledby');
- if (ariaLabelledById.startsWith('accessible-list')) {
- const h1Elements = section.getElementsByTagName('h1');
- for (let j = 0; j < h1Elements.length; j++) {
- const h1Element = h1Elements[j];
- if (h1Element.getAttribute('role') === 'heading' && (h1Element.textContent.trim() === 'Reposts' || h1Element.textContent.trim() === 'Likes' || h1Element.textContent.trim() === 'Quotes')) {
- const cellInnerDivs = section.querySelectorAll('[data-testid="cellInnerDiv"]');
- cellInnerDivs.forEach(cellInnerDiv => {
- const hrefRegex = /href="([^"]*)"/;
- const match = cellInnerDiv.innerHTML.match(hrefRegex);
- if (match && match[1]) {
- const href = match[1];
- if (!hrefList.includes(href)) {
- hrefList.push(href);
- updateHrefsCountDisplay();
- console.log("New href added:", href);
- }
- }
- });
- break;
- }
- }
- }
- }
- }
- }
- function pickWinner() {
- if (hrefList.length > 0) {
- const randomIndex = Math.floor(Math.random() * hrefList.length);
- const selectedHref = hrefList[randomIndex];
- winnerButton.textContent = selectedHref;
- winnerButton.href = selectedHref;
- hrefList.splice(randomIndex, 1);
- updateHrefsCountDisplay();
- } else {
- winnerButton.textContent = "No entries available";
- winnerButton.removeAttribute('href');
- }
- }
- function handlePickWinner() {
- hrefList = [];
- processSections();
- const scrollInterval = setInterval(function() {
- window.scrollBy(0, window.innerHeight);
- scrollAttempts++;
- if (scrollAttempts >= 3) {
- scrollAttempts = 0;
- const prevLength = hrefList.length;
- processSections();
- if (hrefList.length === prevLength) {
- clearInterval(scrollInterval);
- console.log("Reached end. List of hrefs:", hrefList);
- pickWinner();
- }
- }
- }, 1000);
- }
- function handleReroll() {
- pickWinner();
- }
- function updateHrefsCountDisplay() {
- hrefCountDisplay.textContent = `Total hrefs: ${hrefList.length}`;
- }
- const pickWinnerButton = document.createElement('button');
- pickWinnerButton.textContent = 'Pick a Winner';
- pickWinnerButton.addEventListener('click', handlePickWinner);
- document.body.appendChild(pickWinnerButton);
- pickWinnerButton.style.position = 'fixed';
- pickWinnerButton.style.top = '10px';
- pickWinnerButton.style.left = '10px';
- pickWinnerButton.style.backgroundColor = 'green';
- pickWinnerButton.style.color = 'white';
- pickWinnerButton.style.padding = '10px 20px';
- pickWinnerButton.style.border = 'none';
- pickWinnerButton.style.borderRadius = '5px';
- pickWinnerButton.style.cursor = 'pointer';
- const rerollButton = document.createElement('button');
- rerollButton.textContent = 'Reroll';
- rerollButton.addEventListener('click', handleReroll);
- document.body.appendChild(rerollButton);
- rerollButton.style.position = 'fixed';
- rerollButton.style.top = '10px';
- rerollButton.style.left = '150px';
- rerollButton.style.backgroundColor = 'blue';
- rerollButton.style.color = 'white';
- rerollButton.style.padding = '10px 20px';
- rerollButton.style.border = 'none';
- rerollButton.style.borderRadius = '5px';
- rerollButton.style.cursor = 'pointer';
- const winnerButton = document.createElement('a');
- winnerButton.textContent = '- None -';
- document.body.appendChild(winnerButton);
- winnerButton.style.position = 'fixed';
- winnerButton.style.top = '50px';
- winnerButton.style.left = '10px';
- winnerButton.style.backgroundColor = 'blue';
- winnerButton.style.color = 'white';
- winnerButton.style.padding = '10px 20px';
- winnerButton.style.border = 'none';
- winnerButton.style.borderRadius = '5px';
- winnerButton.style.cursor = 'pointer';
- const hrefCountDisplay = document.createElement('span');
- hrefCountDisplay.textContent = `Total hrefs: ${hrefList.length}`;
- document.body.appendChild(hrefCountDisplay);
- hrefCountDisplay.style.position = 'fixed';
- hrefCountDisplay.style.top = '90px';
- hrefCountDisplay.style.left = '10px';
- hrefCountDisplay.style.color = 'black';
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement