Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Youtube Chapters Navigator
- // @namespace http://tampermonkey.net/
- // @version 0.2
- // @description Simulates CTRL+Arrow key presses when mouse is at screen edges with a 2-second delay
- // @match *://*/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- const EDGE_THRESHOLD = 5; // pixels from edge to trigger the event
- const DELAY = 2000; // delay in milliseconds (2 seconds)
- let lastKeyPressTime = 0;
- function simulateKeyPress(keyCode) {
- const currentTime = Date.now();
- if (currentTime - lastKeyPressTime < DELAY) {
- return; // Don't send another key press if not enough time has passed
- }
- const event = new KeyboardEvent('keydown', {
- bubbles: true,
- cancelable: true,
- keyCode: keyCode,
- ctrlKey: true
- });
- document.dispatchEvent(event);
- lastKeyPressTime = currentTime;
- }
- document.addEventListener('mousemove', function(e) {
- const x = e.clientX;
- const windowWidth = window.innerWidth;
- if (x <= EDGE_THRESHOLD) {
- // Left edge - simulate CTRL + Left Arrow
- simulateKeyPress(37);
- } else if (x >= windowWidth - EDGE_THRESHOLD) {
- // Right edge - simulate CTRL + Right Arrow
- simulateKeyPress(39);
- }
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment