| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 request = {action: "should_scroll"} | 5 request = {action: "should_scroll"} |
| 6 | 6 |
| 7 chrome.extension.sendRequest(request, function(response) { | 7 chrome.extension.sendRequest(request, function(response) { |
| 8 if (response.should_scroll) { | 8 if (response.should_scroll) { |
| 9 window.focus(); |
| 9 lastOffset = window.pageYOffset; | 10 lastOffset = window.pageYOffset; |
| 10 function smoothScrollDown() | 11 var start_interval = Math.max(10000, response.scroll_interval); |
| 11 { | 12 function smoothScrollDown() { |
| 12 window.scrollBy(0, response.scroll_by); | 13 window.scrollBy(0, response.scroll_by); |
| 13 if (window.pageYOffset != lastOffset) { | 14 if (window.pageYOffset != lastOffset) { |
| 14 lastOffset = window.pageYOffset; | 15 lastOffset = window.pageYOffset; |
| 15 setTimeout(smoothScrollDown, response.scroll_interval); | 16 setTimeout(smoothScrollDown, response.scroll_interval); |
| 16 } | 17 } else if (response.should_scroll_up) { |
| 17 else { | 18 setTimeout(smoothScrollUp, start_interval); |
| 18 if (response.should_scroll_up) { | |
| 19 setTimeout(smoothScrollUp, 5000); | |
| 20 } | |
| 21 } | 19 } |
| 22 } | 20 } |
| 23 function smoothScrollUp() | 21 function smoothScrollUp() { |
| 24 { | |
| 25 window.scrollBy(0, -1 * response.scroll_by); | 22 window.scrollBy(0, -1 * response.scroll_by); |
| 26 if (window.pageYOffset != lastOffset) { | 23 if (window.pageYOffset != lastOffset) { |
| 27 lastOffset = window.pageYOffset; | 24 lastOffset = window.pageYOffset; |
| 28 if (response.scroll_loop) { | 25 setTimeout(smoothScrollUp, response.scroll_interval); |
| 29 setTimeout(smoothScrollUp, response.scroll_interval); | 26 } else if (response.scroll_loop) { |
| 30 } | 27 setTimeout(smoothScrollDown, start_interval); |
| 31 } | 28 } |
| 32 } | 29 } |
| 33 setTimeout(smoothScrollDown, 10000); | 30 setTimeout(smoothScrollDown, start_interval); |
| 34 } | 31 } |
| 35 }); | 32 }); |
| 36 | 33 |
| OLD | NEW |