Difference between revisions of "User:Charlotte/nookipedia-timeless.js"
From Nookipedia, the Animal Crossing wiki
(fixed issue) |
|||
Line 1: | Line 1: | ||
− | |||
mw.loader.using('mediawiki.util', function () { | mw.loader.using('mediawiki.util', function () { | ||
document.addEventListener('keydown', function (event) { | document.addEventListener('keydown', function (event) { | ||
Line 5: | Line 4: | ||
var activeElement = document.activeElement; | var activeElement = document.activeElement; | ||
− | // Check if the "/" key was pressed | + | // Check if the "/" key was pressed and you're not editing or focusing on an input/textarea |
− | if (event.key === '/' && activeElement.id !== 'searchInput' | + | if ( |
− | // | + | event.key === '/' && |
− | event.preventDefault(); | + | activeElement.id !== 'searchInput' && |
+ | activeElement.tagName !== 'INPUT' && | ||
+ | activeElement.tagName !== 'TEXTAREA' && | ||
+ | !document.body.classList.contains('ve-active') && // Check if the VisualEditor is active | ||
+ | !document.body.classList.contains('mw-editing') // Check if the Wikitext editor is active | ||
+ | ) { | ||
+ | event.preventDefault(); // Prevent default behavior | ||
// Focus the search input field | // Focus the search input field |
Latest revision as of 22:35, September 2, 2024
mw.loader.using('mediawiki.util', function () {
document.addEventListener('keydown', function (event) {
// Get the currently focused element
var activeElement = document.activeElement;
// Check if the "/" key was pressed and you're not editing or focusing on an input/textarea
if (
event.key === '/' &&
activeElement.id !== 'searchInput' &&
activeElement.tagName !== 'INPUT' &&
activeElement.tagName !== 'TEXTAREA' &&
!document.body.classList.contains('ve-active') && // Check if the VisualEditor is active
!document.body.classList.contains('mw-editing') // Check if the Wikitext editor is active
) {
event.preventDefault(); // Prevent default behavior
// Focus the search input field
var searchInput = document.getElementById('searchInput');
if (searchInput) {
searchInput.focus();
}
}
});
});