Bookmarklets/AutoScroll_(after_10s)_medium_speed.bookmarklet.txt

javascript:!function(){var e,t=40;window.autoScroller&&(clearTimeout(window.autoScroller.idleInterval),window.autoScroller.rafId&&cancelAnimationFrame(window.autoScroller.rafId),window.autoScroller.cleanup&&window.autoScroller.cleanup());var n,o,r=!1,i=0,l=500,c=null,u=0,s=!document.hidden,a=!1,d=Date.now();function f(e){const t=[];if(e.shadowRoot)try{const n=e.shadowRoot.querySelectorAll("video");t.push(...Array.from(n));const o=e.shadowRoot.querySelectorAll("*");for(let e of o)t.push(...f(e))}catch(e){}return t}function w(e){if(e.poster&&e.poster.toLowerCase().includes(".gif"))return!0;if(e.src&&e.src.toLowerCase().includes(".gif"))return!0;if(e.currentSrc&&e.currentSrc.toLowerCase().includes(".gif"))return!0;const t=e.querySelectorAll("source");for(let e of t)if(e.src&&e.src.toLowerCase().includes(".gif"))return!0;return!1}function m(){const e=[];let t=document.querySelectorAll("video");e.push(...Array.from(t));const n=document.querySelectorAll("*");for(let t of n)e.push(...f(t));e.push(...function(){const e=[];return document.querySelectorAll("iframe").forEach((function(t){try{if(t.contentDocument&&t.contentWindow){const n=t.contentDocument.querySelectorAll("video");e.push(...Array.from(n))}}catch(e){}})),e}());const o=[];for(var r=0;r<e.length;r++){let t=e[r];try{if(w(t))continue;t.paused||t.ended||o.push(t)}catch(e){}}return o}function h(e){const t=e.getBoundingClientRect();let n,o;if(p===document.scrollingElement||p===document.documentElement||p===document.body)n=window.innerHeight,o=0;else{const e=p.getBoundingClientRect();n=p.clientHeight,o=e.top}const r=t.height,i=t.top-o,l=t.bottom-o;if(l<=0||i>=n)return{visibility:0,distanceToIdeal:1/0,isOptimal:!1};const c=Math.max(0,i),u=(Math.min(n,l)-c)/r,s=(n-r)/2,a=Math.abs(i-s),d=a<50,f=1-Math.abs((i+l)/2-n/2)/(n/2);return{visibility:.7*u+.3*Math.max(0,f),distanceToIdeal:a,isOptimal:d,videoTop:i,idealTop:s}}const v=function(){const e=[];document.querySelectorAll("*").forEach((function(t){const n=getComputedStyle(t);("scroll"===n.overflowY||"auto"===n.overflowY)&&t.scrollHeight>t.clientHeight&&e.push({el:t,scrollHeight:t.scrollHeight})}));const t=document.scrollingElement;return t&&t.scrollHeight>t.clientHeight&&e.push({el:t,scrollHeight:t.scrollHeight}),e}();if(0===v.length)return;v.sort((function(e,t){const n=t.el.clientWidth-e.el.clientWidth;return 0!==n?n:t.scrollHeight-e.scrollHeight}));const p=v[0].el;var g=!1;function y(){Date.now()-d<5e3||(g=!0,clearTimeout(e),e=setTimeout((function(){g=!1,n=null}),6e4),window.autoScroller.idleInterval=e)}function S(e){if(!s)return;if(g)return o=requestAnimationFrame(S),void(window.autoScroller.rafId=o);n||(n=e);const r=function(e){if(e-i>=l){i=e;const t=m();if(0===t.length)return c=null,u=0,a&&(a=!1),!1;let n=null,o=0;t.forEach((function(e){const t=h(e);t.visibility>o&&(n=e,o=t.visibility)})),c=n,u=o}if(c){if(c.paused||c.ended)return c=null,u=0,a&&(a=!1),!1;const e=h(c),t=e.visibility;if(t>.2){if(e.isOptimal){try{c.loop=!1}catch(e){}return a=!0,!0}return a&&(a=!1),!1}if(t<u&&u>.3&&e.isOptimal)return a=!0,!0}return a&&(a=!1),!1}(e);if(r)return o=requestAnimationFrame(S),void(window.autoScroller.rafId=o);a&&(n=e,a=!1);var d=(e-n)/1e3;p.scrollBy(0,t*d),n=e,o=requestAnimationFrame(S),window.autoScroller.rafId=o}function A(){(s=!document.hidden)?r&&(n=null,o=requestAnimationFrame(S),window.autoScroller.rafId=o):o&&(cancelAnimationFrame(o),o=null,window.autoScroller.rafId=null)}window.addEventListener("wheel",y,{passive:!0}),window.addEventListener("touchstart",y,{passive:!0}),window.addEventListener("keydown",y,{passive:!0}),window.addEventListener("mousemove",y,{passive:!0}),document.addEventListener("visibilitychange",A,!1),window.autoScroller={idleInterval:null,rafId:null,cleanup:function(){window.removeEventListener("wheel",y),window.removeEventListener("touchstart",y),window.removeEventListener("keydown",y),window.removeEventListener("mousemove",y),document.removeEventListener("visibilitychange",A)}},r||(r=!0,n=null,o=requestAnimationFrame(S),window.autoScroller.rafId=o)}();