Userscript For Creating A Confirmation Popup Whenever Submitting An Issue Or Posting A Comment Via Pressing Ctrl+enter(the Built-in Hotkey) In Github
Test URL: https://github.com/darkred/test/issues/new GitHub allows in the issues area for a public repo: submitting a new issue with just 1 character as title and no body, and po
Solution 1:
Based on the help by user trespassersW here(I thank him a lot)
i.e. that my code was missing an else
branch:
if (confirm('Are you sure?') == false) {
// ...
} else {
var btn = document.querySelector("#partial-new-comment-form-actions button");
if (btn) btn.click();
}
and that's because the confirm
messagebox clears keyboard events queue.
(therefore the click 'Ok'
action must be done by the script).
Here is a full working script:
// ==UserScript==// @nameGitHub Confirm Create and Close issues// @include https://github.com/*// @grant none// ==/UserScript==
(function () { // Self-Invoking functionfunctioninit() {
// For submitting issues in issue body textarea via Ctrl+Entervar targArea1 = document.querySelector('#issue_body'); // New issue textareafunctionmanageKeyEvents1(zEvent) {
if (zEvent.ctrlKey && zEvent.keyCode === 13) {
if (confirm('Are you sure?') === false) {
zEvent.stopPropagation();
zEvent.preventDefault();
} else {
var btn1 = document.querySelector('.btn-primary');
if (btn1) {btn1.click();}
}
}
}
if (targArea1 !== null) { targArea1.addEventListener('keydown', manageKeyEvents1); }
// ------------------------------------------------------------------------------------------------// For submitting issues in new comment textarea via Ctrl+Entervar targArea2 = document.querySelector('#new_comment_field'); // New comment textareafunctionmanageKeyEvents2(zEvent) {
if (zEvent.ctrlKey && zEvent.keyCode === 13) {
if (confirm('Are you sure?') === false) {
zEvent.stopPropagation();
zEvent.preventDefault();
} else {
var btn2 = document.querySelector('#partial-new-comment-form-actions button');
if (btn2) {btn2.click();}
}
}
}
if (targArea2 !== null) { targArea2.addEventListener('keydown', manageKeyEvents2); }
}
// Page loadinit();
// On pjax (because GitHub uses the History API)document.addEventListener('pjax:end', init);
})();
Post a Comment for "Userscript For Creating A Confirmation Popup Whenever Submitting An Issue Or Posting A Comment Via Pressing Ctrl+enter(the Built-in Hotkey) In Github"