Prevent chat auto focus on Discord desktop and mobile.
当前为
// ==UserScript==
// @name Discord Kill Autofocus
// @description Prevent chat auto focus on Discord desktop and mobile.
// @author C89sd
// @version 0.4
// @match https://discord.com/*
// @namespace https://greasyfork.org/users/1376767
// ==/UserScript==
(function() {
'use strict';
let clickInTextbox = false;
document.addEventListener('mousedown', (event) => {
if (event.target.closest('div[role="textbox"], textarea')) {
clickInTextbox = true;
}
});
document.addEventListener('mouseup', (event) => {
setTimeout(() => {
clickInTextbox = false;
}, 100);
});
function detectAndRemoveFocus(event) {
try {
const target = event.target;
if (!clickInTextbox && target.matches('div[role="textbox"], textarea')) {
target.blur();
}
} finally {
clickInTextbox = false;
};
}
document.addEventListener('focus', detectAndRemoveFocus, true);
})();