Advertisement
YassMes

Untitled

May 2nd, 2025 (edited)
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Scroll Marker with Transparent Layer and Toggle
  3. // @namespace    http://tampermonkey.net/
  4. // @version      2.4
  5. // @description  Shows scroll markers and a transparent overlay in scroll direction. Toggle with Alt+Q.
  6. // @author       X
  7. // @match        *://*/*
  8. // @grant        none
  9. // @run-at       document-end
  10. // ==/UserScript==
  11.  
  12. (function () {
  13.     'use strict';
  14.  
  15.     const markerColor = 'red';
  16.     const markerDuration = 350;
  17.     const toggleOverlayDuration = 1000;
  18.     const shortcutKey = 'KeyQ';
  19.     const shortcutModifier = 'altKey';
  20.     const markerHeight = '4px';
  21.     const throttleDelay = 100;
  22.  
  23.     let enabled = true;
  24.     let previousScrollY = window.scrollY;
  25.     let throttleTimeout = null;
  26.  
  27.     function showMarker(yPos, direction) {
  28.         if (!enabled) return;
  29.  
  30.         const screenY = yPos - window.scrollY;
  31.         if (screenY < 0 || screenY > window.innerHeight) return;
  32.  
  33.         // Marker
  34.         const marker = document.createElement('div');
  35.         marker.style.position = 'fixed';
  36.         marker.style.left = '0';
  37.         marker.style.width = '100%';
  38.         marker.style.height = markerHeight;
  39.         marker.style.backgroundColor = markerColor;
  40.         marker.style.top = `${screenY}px`;
  41.         marker.style.zIndex = '999999';
  42.         marker.style.pointerEvents = 'none';
  43.         marker.style.transition = 'opacity 0.1s';
  44.         document.body.appendChild(marker);
  45.  
  46.         // Transparent layer
  47.         const layer = document.createElement('div');
  48.         layer.style.position = 'fixed';
  49.         layer.style.left = '0';
  50.         layer.style.width = '100%';
  51.         layer.style.backgroundColor = markerColor;
  52.         layer.style.opacity = '0.1';
  53.         layer.style.pointerEvents = 'none';
  54.         layer.style.zIndex = '999998';
  55.  
  56.         if (direction === 'down') {
  57.             // Layer from marker to bottom
  58.             const layerTop = screenY + parseInt(markerHeight);
  59.             layer.style.top = `${layerTop}px`;
  60.             layer.style.height = `calc(100vh - ${layerTop}px)`;
  61.         } else {
  62.             // Layer from top to marker
  63.             layer.style.top = '0';
  64.             layer.style.height = `${screenY}px`;
  65.         }
  66.  
  67.         document.body.appendChild(layer);
  68.  
  69.         // Remove after delay
  70.         setTimeout(() => {
  71.             marker.style.opacity = '0';
  72.             layer.style.opacity = '0';
  73.             setTimeout(() => {
  74.                 marker.remove();
  75.                 layer.remove();
  76.             }, 100);
  77.         }, markerDuration);
  78.     }
  79.  
  80.     function showToggleOverlay(stateText) {
  81.         const overlay = document.createElement('div');
  82.         overlay.textContent = `Scroll marker ${stateText}`;
  83.         overlay.style.position = 'fixed';
  84.         overlay.style.top = '50%';
  85.         overlay.style.left = '50%';
  86.         overlay.style.transform = 'translate(-50%, -50%)';
  87.         overlay.style.background = stateText === 'enabled' ? 'green' : 'red'; // Change color based on state
  88.         overlay.style.color = '#fff';
  89.         overlay.style.padding = '10px';
  90.         overlay.style.borderRadius = '6px';
  91.         overlay.style.fontSize = '16px';
  92.         overlay.style.zIndex = '1000000';
  93.         overlay.style.pointerEvents = 'none';
  94.         overlay.style.transition = 'opacity 0.3s';
  95.         document.body.appendChild(overlay);
  96.  
  97.         setTimeout(() => {
  98.             overlay.style.opacity = '0';
  99.             setTimeout(() => overlay.remove(), 300);
  100.         }, toggleOverlayDuration);
  101.     }
  102.  
  103.     function handleScroll() {
  104.         const currentY = window.scrollY;
  105.         const deltaY = currentY - previousScrollY;
  106.  
  107.         if (deltaY > 0) {
  108.             const previousBottom = previousScrollY + window.innerHeight;
  109.             showMarker(previousBottom, 'down');
  110.         } else if (deltaY < 0) {
  111.             const previousTop = previousScrollY;
  112.             showMarker(previousTop, 'up');
  113.         }
  114.  
  115.         previousScrollY = currentY;
  116.     }
  117.  
  118.     window.addEventListener('scroll', () => {
  119.         if (throttleTimeout) return;
  120.  
  121.         throttleTimeout = setTimeout(() => {
  122.             handleScroll();
  123.             throttleTimeout = null;
  124.         }, throttleDelay);
  125.     }, { passive: true });
  126.  
  127.     window.addEventListener('keydown', (e) => {
  128.         if (e[shortcutModifier] && e.code === shortcutKey) {
  129.             enabled = !enabled;
  130.             showToggleOverlay(enabled ? 'enabled' : 'disabled');
  131.         }
  132.     });
  133. })();
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement