function ____isElementInViewport(el) { //special bonus for those using jQuery if (typeof jQuery === "function" && el instanceof jQuery) { el = el[0]; } var rect = el.getBoundingClientRect(); return ( rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */ rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */ ); } function __isElementInViewport(element) { var rect = element.getBoundingClientRect(); var html = document.documentElement; return ( rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || html.clientHeight) && rect.right <= (window.innerWidth || html.clientWidth) ); } function expand_item_if_to_be(el){ if (!__isElementInViewport(el)){ return ; } console.log(el); var sc = el.getElementsByClassName('the-right-sidebar-of-a-story')[0]; if (sc){ sc.click(); } } function expand_st_in_view(){ var x = document.getElementsByClassName('story_container'); for (var i=0; i -1){ expand_st_in_view(); } } });