Untitled
unknown
javascript
2 years ago
1.9 kB
4
No Index
// ==UserScript==
// @name KG_Main_Page_Navigation
// @namespace klavogonki
// @version 2024-05-13
// @description Fast main page navigation
// @author Patcher
// @match *://klavogonki.ru/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=klavogonki.ru
// @grant none
// ==/UserScript==
(function() {
// Define the URL of the main page
const kgMainPage = 'https://klavogonki.ru/';
// Define the duration threshold for a long press in milliseconds
const longPressDuration = 300;
// Variable to store the time when the right mouse button is pressed down
let mouseDownTime;
// Add event listener for mouse down event
document.addEventListener('mousedown', e => {
// Check if the right mouse button is pressed
if (e.button === 2) {
// Record the current time when the right mouse button is pressed down
mouseDownTime = Date.now();
}
});
// Add event listener for mouse up event
document.addEventListener('contextmenu', e => {
// Check if the right mouse button is released and the current URL is not the main page URL
if (e.button === 2 && window.location.href !== kgMainPage) {
// Calculate the duration of the press by subtracting the mouse down time from the current time
const pressDuration = Date.now() - mouseDownTime;
// Check if the press duration exceeds the long press duration threshold
if (pressDuration >= longPressDuration) {
// Prevent default context menu
e.preventDefault();
// If the press duration is longer than or equal to the threshold, navigate to the main page URL
window.location.href = kgMainPage;
}
}
});
})();Editor is loading...
Leave a Comment