Skip to content

Instantly share code, notes, and snippets.

@izy521
Last active November 12, 2021 06:14
Show Gist options
  • Save izy521/5447b5e483d6b41729ec6ede28325872 to your computer and use it in GitHub Desktop.
Save izy521/5447b5e483d6b41729ec6ede28325872 to your computer and use it in GitHub Desktop.
Use CTRL + Enter to send a Discord Embedified message. You'll need to provide your account token to the code, on line 3. Will be removed if you refresh. Highlighting a selection of your message will let you send only that as the embed, and the rest as a normal message.
(function start_embed_generator(window, document) {
var my_token = "-YOUR_TOKEN_HERE-";
var color_reg = /(\#.+?)(\s|$)/;
var text_bar_color = "rgb(92, 156, 199)";
window.addEventListener('keydown' , handle_event);
window.addEventListener('keyup' , revert_bar );
return !console.log("Embed generator up!");
function handle_event(event) {
var embed, text_bar, text_area, highlighted, not_highlighted;
if (!event.ctrlKey) return;
text_bar = document.getElementsByClassName('channel-textarea-inner')[0];
if (!text_bar) return;
if (!text_bar.style.borderColor) text_bar.style.borderColor = text_bar_color;
if (event.keyCode !== 13) return;
text_area = text_bar.children[1];
if (!text_area || text_area.value === "") return;
if (text_area.selectionStart !== text_area.selectionEnd) {
highlighted = text_area.value.slice(text_area.selectionStart, text_area.selectionEnd);
not_highlighted = text_area.value.replace(highlighted, "");
}
send_request(resolve_channel_id(), format_embed(highlighted || text_area.value), not_highlighted);
return void(text_area.value = "");
}
function send_request(channelID, embed, content) {
var url = `https://discordapp.com/api/v6/channels/${channelID}/messages`;
var opts = {
method: 'POST',
headers: {"Authorization": my_token, "Content-Type": 'application/json'},
body: JSON.stringify({ content: content || "", embed: embed })
};
return fetch(url, opts).catch(console.error);
}
function format_embed(string) {
var match, color = null;
if ( match = string.match(color_reg) ) {
color = parseInt(match[0].slice(1, match[0].length), 16);
string = string.replace(match[0], "");
}
return {
description: string,
color: color || 0,
}
}
function resolve_channel_id() {
var path = window.location.pathname;
return path.slice( path.lastIndexOf("/") + 1, path.length );
}
function revert_bar(event) {
if (event.keyCode !== 17) return;
var text_bar = document.getElementsByClassName('channel-textarea-inner')[0];
if (!text_bar) return;
return text_bar.style.borderColor ? void(text_bar.style.borderColor = "") : false;
}
})(window, document);
@SharkFinPro
Copy link

Nice!

Copy link

ghost commented Feb 8, 2018

not working anymore. try pressing ctrl+enter but its not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment