Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Youtube Chapters Navigator (Edge Mod - Right Edge Seek)
- // @namespace http://tampermonkey.net/
- // @version 0.4
- // @description Simulates CTRL+Arrow key presses when mouse is at screen edges (left or right), 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 to simulate Ctrl + Arrow key presses
- function simulateCtrlKeyPress(keyCode) {
- const currentTime = Date.now();
- if (currentTime - lastKeyPressTime < DELAY) {
- return; // Don't send another key press if not enough time has passed
- }
- // Użyj 'keyup' dla keyCode 39, 'keydown' dla innych
- const eventType = keyCode === 39 ? 'keyup' : 'keydown';
- const event = new KeyboardEvent(eventType, {
- bubbles: true,
- cancelable: true,
- keyCode: keyCode,
- ctrlKey: true
- });
- document.dispatchEvent(event);
- lastKeyPressTime = currentTime;
- }
- document.addEventListener('mousemove', function(e) {
- const x = e.clientX;
- const y = e.clientY;
- const windowWidth = window.innerWidth;
- const windowHeight = window.innerHeight;
- if (x <= EDGE_THRESHOLD) {
- // Left edge - simulate CTRL + Left Arrow
- simulateCtrlKeyPress(37);
- } else if (x >= windowWidth - EDGE_THRESHOLD) {
- // Right edge - simulate CTRL + Right Arrow with keyup
- simulateCtrlKeyPress(39);
- }
- // Bottom edge - no action (możesz dodać inną akcję, jeśli potrzebna)
- });
- })();
Advertisement