Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- // INFORMATION
- // ===========
- // COPY THIS CODE INTO YOU BROWSER (chrome version >= 55)
- //
- // Description:
- // It will automatically change the client viewport
- // downwards. If the client viewport have reach the
- // the bottom the client viewport is moved to the
- // top of the page.
- //
- // Author:
- // thorgeir <thorgeir.sigurdsson@CYREN.com>
- //
- // CONSTANST
- // =========
- // CONTAINER:
- // A class name of an element that has its
- // Y coordinate at the bottom of the page.
- // TIME_INTERVAL:
- // The interval measures the time during which
- // the client viewport is visible.
- // DOWN:
- // The proportion of the client viewport height.
- // e.g. if DOWN equals 2 the viewport goes downwards
- // the half size of the client viewport height.
- const CONTAINER='main-view'
- const TIME_INTERVAL=8000//ms = 8 sec
- const DOWN=2
- // Expand all the views.
- document.querySelectorAll('.dash-row-header-title')
- .forEach(function(element) { element.click(); });
- //
- // HELPER FUNCTIONS
- //
- // Positioning the viewport
- // at the top of the page.
- function topPage(){
- console.log( 'Go to top' )
- window.scrollTo(0, 0);
- }
- // Return the height of
- // the clients viewport
- function clientHeight(){
- return window.innerHeight;
- }
- // Moves the client viewport downwards
- function down(){
- console.log( 'Scroll down by', clientHeight()/DOWN)
- window.scrollBy(0, clientHeight()/DOWN);
- }
- // Return True if the client
- // viewport have reach the bottom
- // of the page otherwise False.
- function atBottom() {
- var main_view = document.getElementsByClassName(CONTAINER)
- var maxY = main_view[0].offsetHeight
- if ((clientHeight() + window.scrollY) >= maxY) {
- console.log( 'Reach the bottom', true )
- return true
- } else {
- console.log( 'Reach the bottom', false )
- return false
- }
- }
- // Copy from stackoverflow
- // -> http://stackoverflow.com/questions/951021
- function sleep(ms) {
- return new Promise(resolve => setTimeout(resolve, ms));
- }
- //
- // THE LOGIC
- //
- // Ping Pong calls between these two functions.
- // Waits for a given milliseconds
- // and then starts the work.
- async function wait( ms ) {
- console.log('Taking a break...');
- var counter = counter - 1;
- await sleep( ms );
- work();
- }
- // Move the client viewport down
- // or too the top of the page and
- // then wait for a while.
- function work() {
- if( atBottom() ){
- topPage();
- } else{
- down();
- }
- wait( TIME_INTERVAL );
- }
- // Start the process
- work()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement