SheridanCoriana6

Youtube Chapters Navigator

Apr 12th, 2025
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.41 KB | Source Code | 0 0
  1. // ==UserScript==
  2. // @name         Youtube Chapters Navigator
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.2
  5. // @description  Simulates CTRL+Arrow key presses when mouse is at screen edges with a 2-second delay
  6. // @match        *://*/*
  7. // @grant        none
  8. // ==/UserScript==
  9. (function() {
  10.     'use strict';
  11.     const EDGE_THRESHOLD = 5; // pixels from edge to trigger the event
  12.     const DELAY = 2000; // delay in milliseconds (2 seconds)
  13.     let lastKeyPressTime = 0;
  14.     function simulateKeyPress(keyCode) {
  15.         const currentTime = Date.now();
  16.         if (currentTime - lastKeyPressTime < DELAY) {
  17.             return; // Don't send another key press if not enough time has passed
  18.         }
  19.         const event = new KeyboardEvent('keydown', {
  20.             bubbles: true,
  21.             cancelable: true,
  22.             keyCode: keyCode,
  23.             ctrlKey: true
  24.         });
  25.         document.dispatchEvent(event);
  26.         lastKeyPressTime = currentTime;
  27.     }
  28.     document.addEventListener('mousemove', function(e) {
  29.         const x = e.clientX;
  30.         const windowWidth = window.innerWidth;
  31.         if (x <= EDGE_THRESHOLD) {
  32.             // Left edge - simulate CTRL + Left Arrow
  33.             simulateKeyPress(37);
  34.         } else if (x >= windowWidth - EDGE_THRESHOLD) {
  35.             // Right edge - simulate CTRL + Right Arrow
  36.             simulateKeyPress(39);
  37.         }
  38.     });
  39. })();
Tags: tampermonkey
Advertisement
Add Comment
Please, Sign In to add comment