2024. 7. 5. 23:31
웹
https://x.com/ahzkwid/status/1834648573582913679
사용법
let uniqueUserIds = new Set();
function scrollAndCheck() {
let previousElements = new Set();
let stack = 0;
let interval = setInterval(() => {
let currentElements = getUserCellElements();
if (setsAreEqual(previousElements, currentElements)) {
if (stack < 2) {
stack++;
} else {
clearInterval(interval);
executeLottery();
}
} else {
previousElements = currentElements;
stack = 0;
}
window.scrollTo(0, document.body.scrollHeight);
}, 1000);
}
function getUserCellElements() {
let userCells = document.querySelectorAll('[data-testid="UserCell"]');
let currentIds = new Set();
userCells.forEach(cell => {
let userId = cell.innerText.split('\n')[1].trim();
currentIds.add(userId);
});
currentIds.forEach(id => uniqueUserIds.add(id));
return currentIds;
}
function executeLottery() {
let userCells = Array.from(uniqueUserIds);
let count = Math.min(3, userCells.length);
let list = [];
for (let i = 0; i < count; i++) {
let rand = Math.floor(Math.random() * userCells.length);
list.push(userCells[rand]);
userCells.splice(rand, 1);
}
console.log(list);
alert("RT: " + uniqueUserIds.size + "\nWinners:\n" + list.join('\n'));
}
function setsAreEqual(set1, set2) {
if (set1.size !== set2.size) {
return false;
}
for (let item of set1) {
if (!set2.has(item)) {
return false;
}
}
return true;
}
scrollAndCheck();
https://gist.github.com/ahzkwid/7efe17a7fbe60036390325ef84011cec
'웹' 카테고리의 다른 글
자주 쓰는 셀레니움 C# 코드 (0) | 2024.10.25 |
---|---|
셀레니움 C# 설치 및 사용법 (0) | 2024.04.21 |
자주 쓰는 크롤링 관련 코드 (0) | 2023.10.16 |