@@ -8,9 +8,11 @@ export default {
88 } ,
99 description : {
1010 en : `Scroll smoothly on all websites with your mouse and keyboard.<br/>
11- Smooth like when you scroll this extension.<br/>` ,
11+ Smooth like when you scroll this extension.<br/><br/>
12+ Support middle click to scroll.` ,
1213 vi : `Cuộn chuột siêu mượt cho mọi trang web.<br/>
13- Mượt như khi cuộn chuột trong extension này vậy.<br/>` ,
14+ Mượt như khi cuộn chuột trong extension này vậy.<br/><br/>
15+ Hỗ trợ scroll khi bấm chuột giữa.` ,
1416 video : "https://www.smoothscroll.net/mac/img/vid/Demo-Mac-720p.mp4" ,
1517 } ,
1618 badges : [ BADGES . new ] ,
@@ -296,19 +298,28 @@ export function enableSmoothScroll() {
296298 }
297299 } , 1 ) ;
298300 }
301+ const dateNow = ( function ( ) {
302+ return window . performance && performance . now
303+ ? function ( ) {
304+ return performance . now ( ) ;
305+ }
306+ : function ( ) {
307+ return Date . now ( ) ;
308+ } ;
309+ } ) ( ) ;
299310 /************************************************
300311 * SCROLLING
301312 ************************************************/
302313 let que = [ ] ;
303314 let pending = null ;
304- let lastScroll = Date . now ( ) ;
315+ let lastScroll = dateNow ( ) ;
305316 /**
306317 * Pushes scroll actions to the scrolling queue.
307318 */
308319 function scrollArray ( elem , left , top ) {
309320 directionCheck ( left , top ) ;
310321 if ( options . accelerationMax != 1 ) {
311- let now = Date . now ( ) ;
322+ let now = dateNow ( ) ;
312323 let elapsed = now - lastScroll ;
313324 if ( elapsed < options . accelerationDelta ) {
314325 let factor = ( 1 + 50 / elapsed ) / 2 ;
@@ -318,15 +329,15 @@ export function enableSmoothScroll() {
318329 top *= factor ;
319330 }
320331 }
321- lastScroll = Date . now ( ) ;
332+ lastScroll = dateNow ( ) ;
322333 }
323334 // push a scroll command
324335 que . push ( {
325336 x : left ,
326337 y : top ,
327338 lastX : left < 0 ? 0.99 : - 0.99 ,
328339 lastY : top < 0 ? 0.99 : - 0.99 ,
329- start : Date . now ( ) ,
340+ start : dateNow ( ) ,
330341 } ) ;
331342 // don't act if there's a pending frame loop
332343 if ( pending ) {
@@ -341,7 +352,7 @@ export function enableSmoothScroll() {
341352 elem . style . scrollBehavior = "auto" ;
342353 }
343354 let step = function ( time ) {
344- let now = Date . now ( ) ;
355+ let now = dateNow ( ) ;
345356 let scrollX = 0 ;
346357 let scrollY = 0 ;
347358 for ( let i = 0 ; i < que . length ; i ++ ) {
@@ -740,7 +751,7 @@ export function enableSmoothScroll() {
740751 } ) ;
741752 if ( ! tp )
742753 chrome . storage . local . set ( {
743- lastDiscreetWheel : Date . now ( ) ,
754+ lastDiscreetWheel : dateNow ( ) ,
744755 } ) ;
745756 } , 1000 ) ;
746757 return tp ;
@@ -957,18 +968,6 @@ export function enableSmoothScroll() {
957968 addEvent ( "mousedown" , remove ) ;
958969 addEvent ( "keydown" , remove ) ;
959970 }
960- /**
961- * performance.now with fallback
962- */
963- let dateNow = ( function ( ) {
964- return window . performance && performance . now
965- ? function ( ) {
966- return performance . now ( ) ;
967- }
968- : function ( ) {
969- return Date . now ( ) ;
970- } ;
971- } ) ( ) ;
972971
973972 addEvent ( "mousedown" , mousedown ) ;
974973 if ( document . readyState === "complete" ) init ( ) ;
0 commit comments