Advertisement
emerginginstance

Untitled

Nov 12th, 2021
829
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Scroll to top button visible when Videos paused
  3. // @namespace    http://tampermonkey.net/
  4. // @version      1
  5. // @include      *
  6. // @grant        none
  7. // @run-at       document-idle
  8. // ==/UserScript==
  9.  
  10. (function() {
  11.     function playback_checker() {
  12.         var videos_active = false
  13.  
  14.         Array.from(document.querySelectorAll('video')).forEach(video => {
  15.             if(!video.paused) {
  16.                 videos_active = true;
  17.             }
  18.         });
  19.  
  20.         return videos_active;
  21.     }
  22.  
  23.     function create_button() {
  24.        
  25.         var button = document.getElementById('userScriptBtn');
  26.         if(button) {
  27.             button.parentNode.removeChild(button);
  28.         }
  29.        
  30.         button = document.createElement("BUTTON");
  31.         button.innerHTML = "Top";
  32.         button.onclick = function () {
  33.             window.scrollTo(0, 0);
  34.             try {
  35.                 $(window).scrollTop(0);
  36.             } catch {
  37.             }
  38.         };
  39.         button.style.position = "absolute";
  40.         button.style.width = '100px'
  41.         button.style.right = '10px'
  42.         button.style.zIndex= 2147483647;
  43.         button.style.top   = ((window.screen.height - document.body.getBoundingClientRect().top - 50) + "px");
  44.         button.style.visibility = playback_checker() ? "hidden" : "";
  45.         button.setAttribute("id", "userScriptBtn");
  46.         document.body.appendChild(button);
  47.     }
  48.  
  49.     function button_visibility() {
  50.         var button = document.getElementById('userScriptBtn');
  51.         if(button) {
  52.             button.style.visibility = playback_checker() ? "hidden" : "";
  53.         }
  54.     }
  55.  
  56.     create_button();
  57.     document.body.onscroll = create_button;
  58.     setInterval(button_visibility, 100);
  59.    
  60. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement