Skip to content

Instantly share code, notes, and snippets.

@dvingerh
Created October 25, 2023 17:17
Show Gist options
  • Save dvingerh/70bce4ec7880a2f0c3310b38e461c457 to your computer and use it in GitHub Desktop.
Save dvingerh/70bce4ec7880a2f0c3310b38e461c457 to your computer and use it in GitHub Desktop.
discord.altmessagesendbutton.user.js
// ==UserScript==
// @name Discord Add Send Button
// @description Discord Add Send Button
// @namespace Discord Add Send Button
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// @require https://raw.githubusercontent.com/pie6k/jquery.initialize/master/jquery.initialize.min.js
// @match *://discord.com/*
// ==/UserScript==
const buttonHTML = `<div class="separator__8424b "><div class="send-button buttonContainer__9b459"><button aria-label="Send Message" type="button" disabled="" class="button__8d734 button_afdfd9 lookBlank__7ca0a colorBrand_b2253e grow__4c8a4"><div class="contents_fb6220 button_f0455c innerButton_debeee"><div style="opacity: 1; transform: none;" class="buttonWrapper__69593 buttonChild__7b90d disabled__74c03"><svg aria-hidden="true" role="img" class="sendIcon__461ff" width="16" height="16" viewBox="0 0 16 16"><path d="M8.2738 8.49222L1.99997 9.09877L0.349029 14.3788C0.250591 14.691 0.347154 15.0322 0.595581 15.246C0.843069 15.4597 1.19464 15.5047 1.48903 15.3613L15.2384 8.7032C15.5075 8.57195 15.6781 8.29914 15.6781 8.00007C15.6781 7.70101 15.5074 7.4282 15.2384 7.29694L1.49839 0.634063C1.20401 0.490625 0.852453 0.535625 0.604941 0.749376C0.356493 0.963128 0.259941 1.30344 0.358389 1.61563L2.00932 6.89563L8.27093 7.50312C8.52405 7.52843 8.71718 7.74125 8.71718 7.99531C8.71718 8.24938 8.52406 8.46218 8.27093 8.4875L8.2738 8.49222Z" fill="currentColor"></path></svg></div></div></button></div></div>`;
const button2HTML = `<div class="separator__8424b"><div class="buttonContainer__9b459"><button id="send-button" aria-label="Send Message" type="button" class="button__8d734 button_afdfd9 lookBlank__7ca0a colorBrand_b2253e grow__4c8a4"><div class="contents_fb6220 button_f0455c innerButton_debeee"><div style="opacity: 1; transform: none;" class="buttonWrapper__69593 buttonChild__7b90d activeButtonChild__6e162"><svg aria-hidden="true" role="img" class="sendIcon__461ff" width="16" height="16" viewBox="0 0 16 16"><path d="M8.2738 8.49222L1.99997 9.09877L0.349029 14.3788C0.250591 14.691 0.347154 15.0322 0.595581 15.246C0.843069 15.4597 1.19464 15.5047 1.48903 15.3613L15.2384 8.7032C15.5075 8.57195 15.6781 8.29914 15.6781 8.00007C15.6781 7.70101 15.5074 7.4282 15.2384 7.29694L1.49839 0.634063C1.20401 0.490625 0.852453 0.535625 0.604941 0.749376C0.356493 0.963128 0.259941 1.30344 0.358389 1.61563L2.00932 6.89563L8.27093 7.50312C8.52405 7.52843 8.71718 7.74125 8.71718 7.99531C8.71718 8.24938 8.52406 8.46218 8.27093 8.4875L8.2738 8.49222Z" fill="currentColor"></path></svg></div></div></button></div></div>`;
$("div[class*='textAreaSlate_']").initialize(function() {
if ($(this).parent().html().indexOf("uploadInput_") == -1) {
$(this).parent().prepend(buttonHTML);
}
else {
$(this).parent().find("div[class*='buttons_']").prepend(button2HTML);
}
});
$("body").on("click", "button#send-button", function(e){
const keyPressEvent = new KeyboardEvent("keydown", {key: "Enter", code: "Enter", which: 13, keyCode: 13, bubbles: true});
Object.defineProperties(keyPressEvent, {keyCode: {value: 13}, which: {value: 13}});
var textArea = $("div[class*='slateTextArea_']").last();
$(textArea).attr("tabindex", '0').focus();
$(textArea)[0].dispatchEvent(keyPressEvent);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment