diff --git a/README.md b/README.md index 6bc48e5..09368bf 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,25 @@ # web-scroller -A utility program written in JavaScript to scroll a web page with infinity scroll capability (social media). When you start the program, it begins scrolling the current page, and will continue scrolling as additional content is loaded. It does not stop until it hits the configured limit or the page has legitimately reached its end. +A utility program written in JavaScript to scroll a web page with infinity scroll capability (social media). When you start the program, it begins scrolling the current page, and will continue scrolling as additional content is loaded. -## Running the Program +The scroller doesn't stop until it hits the configured limit or the page has legitimately reached its end. -Just copy the text of the [web-scroller.js](web-scroller.js) file into your browser's console and press ENTER. The script does not communicate with any network resources at all. It simply scrolls the current page with providions for the page to dynamically grow (infinity scroll, social media, blogs, etc.) \ No newline at end of file +## Running The Program + +Just copy the text of the [web-scroller.js](web-scroller.js) file into your browser's console and press ENTER. The script does not communicate with any network resources at all. It simply scrolls the current page with providions for the page to dynamically grow (infinity scroll, social media, blogs, etc.) + +## Controlling The Program + +The following control variables are offered by the program. + +### TOP_MARGIN +Specifies the number of pixels to use as a top margin when scrolling begins. + +### SCROLL_SPEED +Specifies the number of pixels moved by the scroller per frame. + +### START_DELAY_MS +Specifies a number of milliseconds to wait at the margin before scrolling begins. Useful for startup delays that give you time to hit "record" before scrolling begins. + +### HEIGHT +The maximum height of the document. \ No newline at end of file diff --git a/web-scroller.js b/web-scroller.js index b05ef49..9950f8c 100644 --- a/web-scroller.js +++ b/web-scroller.js @@ -2,21 +2,21 @@ (async ( ) => { - var topMargin = 0; // set to top margin you want for the page scroller - var scrollSpeed = 2; // number of pixels to scroll per frame - var startDelayMs = 0; // set startup delay in milliseconds - var height = 200000; // set to max distance you want to scroll + const TOP_MARGIN = 0; // set to top margin you want for the page scroller + const SCROLL_SPEED = 2; // number of pixels to scroll per frame + const START_DELAY_MS = 0; // set startup delay in milliseconds + const HEIGHT = 200000; // set to max distance you want to scroll - var y = topMargin; - var paused = false; + let y = TOP_MARGIN; + let paused = false; function update ( ) { try { if (!paused) { window.scrollTo(0, y); - y += scrollSpeed; + y += SCROLL_SPEED; } - if (y < height) { + if (y < HEIGHT) { window.requestAnimationFrame(update); } } catch (error) { @@ -26,7 +26,7 @@ try { window.scrollTo(0, y); - window.setTimeout(update, startDelayMs); + window.setTimeout(update, START_DELAY_MS); } catch (error) { console.log('scroller has failed', error); }