Last active
July 14, 2020 19:56
-
-
Save blowery/d22af25cc62989c4863f1d723466d966 to your computer and use it in GitHub Desktop.
Autoscroller
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
(function (pixelsToScroll) { | |
const byteFormatter = new Intl.NumberFormat(undefined, { | |
style: "unit", | |
unit: "megabyte", | |
maximumFractionDigits: 0, | |
minimumFractionDigits: 0, | |
}); | |
const numberFormatter = new Intl.NumberFormat(); | |
const formatBytes = (bytes) => byteFormatter.format(bytes / (1024 * 1024)); | |
const formatPercentage = (dec) => `${Math.round(100 * dec)}%`; | |
function stats() { | |
const m = window.performance.memory; | |
console.log( | |
"Memory: %s used of %s (%s)", | |
formatBytes(m.usedJSHeapSize), | |
formatBytes(m.totalJSHeapSize), | |
formatPercentage(m.usedJSHeapSize / m.totalJSHeapSize) | |
); | |
console.log( | |
"Position: %s", | |
numberFormatter.format(document.body.scrollHeight) | |
); | |
console.log( | |
"Elements in timeline: %s", | |
numberFormatter.format(document.getElementsByClassName("_1DxdS").length) | |
); | |
} | |
function scrollToBottom() { | |
window.scrollTo({ top: document.body.scrollHeight, behavior: "smooth" }); | |
} | |
let nextTurn; | |
function scrollPixels() { | |
if (document.body.scrollHeight < pixelsToScroll) { | |
scrollToBottom(); | |
stats(); | |
nextTurn = setTimeout(scrollPixels, 2000); | |
} else { | |
stats(); | |
console.log( | |
"%s posts, %s ads in timeline", | |
numberFormatter.format( | |
document.querySelectorAll("._1DxdS._2jOH-").length | |
), | |
numberFormatter.format( | |
document.querySelectorAll("._1DxdS:not(._2jOH-)").length | |
) | |
); | |
} | |
} | |
scrollPixels(); | |
window._stop = () => { | |
console.log("stopping"); | |
clearInterval(nextTurn); | |
stats(); | |
console.log( | |
"Elements in timeline: %s", | |
numberFormatter.format(document.getElementsByClassName("_1DxdS").length) | |
); | |
}; | |
})(500000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment