Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Scroll to top button visible when Videos paused
- // @namespace http://tampermonkey.net/
- // @version 1
- // @include *
- // @grant none
- // @run-at document-idle
- // ==/UserScript==
- (function() {
- function playback_checker() {
- var videos_active = false
- Array.from(document.querySelectorAll('video')).forEach(video => {
- if(!video.paused) {
- videos_active = true;
- }
- });
- return videos_active;
- }
- function create_button() {
- var button = document.getElementById('userScriptBtn');
- if(button) {
- button.parentNode.removeChild(button);
- }
- button = document.createElement("BUTTON");
- button.innerHTML = "Top";
- button.onclick = function () {
- window.scrollTo(0, 0);
- try {
- $(window).scrollTop(0);
- } catch {
- }
- };
- button.style.position = "absolute";
- button.style.width = '100px'
- button.style.right = '10px'
- button.style.zIndex= 2147483647;
- button.style.top = ((window.screen.height - document.body.getBoundingClientRect().top - 50) + "px");
- button.style.visibility = playback_checker() ? "hidden" : "";
- button.setAttribute("id", "userScriptBtn");
- document.body.appendChild(button);
- }
- function button_visibility() {
- var button = document.getElementById('userScriptBtn');
- if(button) {
- button.style.visibility = playback_checker() ? "hidden" : "";
- }
- }
- create_button();
- document.body.onscroll = create_button;
- setInterval(button_visibility, 100);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement