beehaw.org Ctrl + Enter to submit comment 2
当前为
// ==UserScript==
// @name beehaw.org Ctrl + Enter to submit comment
// @namespace english
// @description beehaw.org Ctrl + Enter to submit comment 2
// @include http*://*who.is*
// @version 1.2
// @run-at document-end
// @license MIT
// @grant GM_addStyle
// ==/UserScript==
// Main - CSS hides two classes - video add box, and call to action box under it. - also social media
document.body.addEventListener('keydown', (event) => {
if(event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
event.target.form?.submit();
}
});
var keyboardEvent = document.createEvent('KeyboardEvent');
var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? 'initKeyboardEvent' : 'initKeyEvent';
keyboardEvent[initMethod](
'keydown', // event type: keydown, keyup, keypress
true, // bubbles
true, // cancelable
window, // view: should be window
false, // ctrlKey
false, // altKey
false, // shiftKey
false, // metaKey
9, // keyCode: unsigned long - the virtual key code, else 0
0, // charCode: unsigned long - the Unicode character associated with the depressed key, else 0
);
document.dispatchEvent(keyboardEvent);
keyboardEvent = document.createEvent('KeyboardEvent');
initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? 'initKeyboardEvent' : 'initKeyEvent';
keyboardEvent2[initMethod](
'keydown', // event type: keydown, keyup, keypress
true, // bubbles
true, // cancelable
window, // view: should be window
false, // ctrlKey
false, // altKey
false, // shiftKey
false, // metaKey
13, // keyCode: unsigned long - the virtual key code, else 0
0, // charCode: unsigned long - the Unicode character associated with the depressed key, else 0
);
document.dispatchEvent(keyboardEvent);
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = ' ';
document.getElementsByTagName('head')[0].appendChild(style);