Last active
November 16, 2022 13:55
-
-
Save tambourine-man/03c08e7dc4a920e88de7947f77877658 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let followingURL = []; | |
let locked = false; | |
let prevScrollPos; | |
function onlyUnique(value, index, self) { | |
return self.indexOf(value) === index; | |
} | |
const running = setInterval(() => { | |
if (locked) return; | |
locked = true; | |
const backwardScroll = document.body.scrollHeight - window.innerHeight; | |
const scrollIndex = backwardScroll > 0 ? backwardScroll : 0; | |
if ( prevScrollPos === scrollIndex ) { | |
clearInterval(running); | |
// after it's done | |
var uniq = followingURL.filter(onlyUnique); | |
var followingStr = uniq.join('\r\n'); | |
var downloadLink = document.createElement('a'); | |
downloadLink.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(followingStr)); | |
downloadLink.setAttribute('download', "following.txt"); | |
downloadLink.innerText="download me"; | |
downloadLink.style.cssText="position: fixed;top: 0;left: 0;background: rgb(0 0 0 / 75%);color: #fff;width: 100%;height: 100%;text-align: center;line-height: 100vh;"; | |
document.body.appendChild(downloadLink); | |
} else { | |
prevScrollPos = scrollIndex; | |
} | |
let following = document.querySelectorAll('[data-testid=cellInnerDiv]'); | |
following.forEach(item => { | |
const userUrl = item.querySelector('a')?.href; | |
if ( userUrl ) { | |
followingURL.push( userUrl ); | |
} | |
}); | |
console.log('Scrolled to new position ', scrollIndex); | |
window.scrollTo(0, scrollIndex); | |
locked = false; | |
}, 5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment