Advertisement
Guest User

SA random attachment scroller

a guest
Nov 29th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.25 KB | None | 0 0
  1. <html>
  2.   <head>
  3.     <script language="JavaScript">
  4.       var wrapper, content, test;
  5.       var more  = ''
  6.       var imgIndex = 0;
  7.      
  8.       function getRandomAttachment() {
  9.         min = Math.ceil(999999);
  10.         max = Math.floor(100000);
  11.         res = Math.floor(Math.random() * (max - min) + min);
  12.         return `<img src="https://forums.somethingawful.com/attachment.php?attachmentid=${res}"></img>`
  13.       }
  14.  
  15.       function scroller() {
  16.         console.log('scroll height: ', window.scrollY)
  17.         console.log('imgIndex: ', imgIndex)
  18.         console.log('last image height: ', document.body.children[0].children[imgIndex].y)
  19.         if (
  20.           (window.innerHeight + window.scrollY) >= document.body.children[0].children[imgIndex].y - 2
  21.         ) {
  22.           console.log('hit bottom')
  23.           content.innerHTML += getRandomAttachment();
  24.           imgIndex += 1;
  25.         }
  26.       }
  27.     </script>
  28.   </head>
  29.  
  30.   <body>
  31.       <div id="content" style="height: 100vh;"></div>
  32.  
  33.     <script language="JavaScript">
  34.       content = document.getElementById("content");
  35.       content.innerHTML = getRandomAttachment();
  36.  
  37.       if (window.addEventListener)
  38.       window.addEventListener("scroll", scroller, false);
  39.     </script>
  40.   </body>
  41. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement