Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function searchForPosts() {
- var elements = document.querySelectorAll('._5jmm');
- return elements;
- }
- function isElementInViewport(el) {
- var rect = el.getBoundingClientRect();
- return rect.bottom > 0 &&
- rect.right > 0 &&
- rect.left < (window.innerWidth || document.documentElement.clientWidth) /* or $(window).width() */ &&
- rect.top < (window.innerHeight || document.documentElement.clientHeight) /* or $(window).height() */;
- }
- function appendToRemove(posts) {
- let found = false;
- let toRemove = [];
- for (let i=0; i<posts.length; i++) {
- if (isElementInViewport(posts[i]) === true) {
- found = true;
- } else {
- if (found === true)
- toRemove.push(posts[i]);
- }
- }
- return toRemove;
- }
- function removeOutOutOfViewport(toRemove) {
- toRemove.forEach((el) => {
- console.log('Removing element');
- el.innerHTML = '';
- });
- }
- function clearMemory () {
- console.log('Running');
- posts = searchForPosts();
- postsToRemove = appendToRemove(posts);
- removeOutOutOfViewport(postsToRemove);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement