Skip to content

Instantly share code, notes, and snippets.

@onnowhere
Last active November 2, 2023 14:47
Show Gist options
  • Save onnowhere/339f0150add83a0011fc8fa89ccb7605 to your computer and use it in GitHub Desktop.
Save onnowhere/339f0150add83a0011fc8fa89ccb7605 to your computer and use it in GitHub Desktop.
Discord Emoji Copy Bookmarklet

Save emojiCopyBookmarklet.js as a bookmarklet in your browser by adding a new bookmark and pasting the script as the link. Clicking the bookmarklet will enable emoji copy in your browser. Alternatively, run the code in your browser or app console.

Usage

  • Left click on an emoji or sticker to write it into the textbox as a link to a resized 48x48 pixel version of the image
    • If the emoji or sticker can be used normally, it will be inserted as is instead of a link
  • Right click on any emoji or sticker to copy the resized image link to your clipboard
let getEmojiLink = function(emoji) {
return emoji.querySelector("img").src.replace(/size=[0-9]+/, "size=48");
};
let addEmojiCopy = function() {
document.querySelectorAll("[id^=emoji-picker-grid-]").forEach((emoji) => {
if (disabledEmoji = emoji.querySelector("[class*=emojiItemDisabled]")) {
emoji.onclick = function() {
document.querySelector("[class*=emojiButton]").click();
const textbox = document.querySelector("[role=textbox]");
textbox.dispatchEvent(new InputEvent("beforeinput", {data: getEmojiLink(emoji), inputType: "insertText"}));
textbox.dispatchEvent(new FocusEvent("focusin"));
}
disabledEmoji.classList.forEach(function(className) {
if (className.startsWith("emojiItemDisabled")) {disabledEmoji.classList.remove(className);}
});
}
emoji.onmouseup = function(event) {
if (event.which === 3) {
navigator.clipboard.writeText(getEmojiLink(emoji));
}
};
});
};
let getStickerLink = function(sticker) {
return sticker.querySelector("img").src.replace(/size=[0-9]+/, "size=160");
};
let addStickerCopy = function() {
document.querySelectorAll("[id^=sticker-picker-grid-]").forEach((sticker) => {
if (disabledSticker = sticker.querySelector("[class*=stickerUnsendable]")) {
sticker.onclick = function() {
document.querySelector("[class*=emojiButton]").click();
document.querySelector("[class*=emojiButton]").click();
const textbox = document.querySelector("[role=textbox]");
textbox.dispatchEvent(new InputEvent("beforeinput", {data: getStickerLink(sticker), inputType: "insertText"}));
textbox.dispatchEvent(new FocusEvent("focusin"));
}
disabledSticker.classList.forEach(function(className) {
if (className.startsWith("stickerUnsendable")) {disabledSticker.classList.remove(className);}
});
}
sticker.onmouseup = function(event) {
if (event.which === 3) {
navigator.clipboard.writeText(getStickerLink(sticker));
}
};
});
};
document.onclick = function() {
try {
addEmojiCopy();
document.querySelector("[data-ref-id^=emoji-picker-grid]").querySelector("[class^=scroller]").onscroll = addEmojiCopy;
const emojiPicker = document.querySelector("#emoji-picker-tab-panel");
emojiPicker.onmousemove = addEmojiCopy;
emojiPicker.onkeyup = addEmojiCopy;
} catch (err) {}
setTimeout(function() {
try {
addStickerCopy();
document.querySelector("[data-ref-id^=sticker-picker-grid]").querySelector("[class^=scroller]").onscroll = addStickerCopy;
const stickerPicker = document.querySelector("#sticker-picker-tab-panel");
stickerPicker.onmousemove = addStickerCopy;
stickerPicker.onkeyup = addStickerCopy;
} catch (err) {}
}, 200);
};
javascript:(function(){let getEmojiLink=function(e){return e.querySelector("img").src.replace(/size=[0-9]+/,"size=48")},addEmojiCopy=function(){document.querySelectorAll("[id^=emoji-picker-grid-]").forEach((e=>{(disabledEmoji=e.querySelector("[class*=emojiItemDisabled]"))&&(e.onclick=function(){document.querySelector("[class*=emojiButton]").click();const t=document.querySelector("[role=textbox]");t.dispatchEvent(new InputEvent("beforeinput",{data:getEmojiLink(e),inputType:"insertText"})),t.dispatchEvent(new FocusEvent("focusin"))},disabledEmoji.classList.forEach((function(e){e.startsWith("emojiItemDisabled")&&disabledEmoji.classList.remove(e)}))),e.onmouseup=function(t){3===t.which&&navigator.clipboard.writeText(getEmojiLink(e))}}))},getStickerLink=function(e){return e.querySelector("img").src.replace(/size=[0-9]+/,"size=160")},addStickerCopy=function(){document.querySelectorAll("[id^=sticker-picker-grid-]").forEach((e=>{(disabledSticker=e.querySelector("[class*=stickerUnsendable]"))&&(e.onclick=function(){document.querySelector("[class*=emojiButton]").click(),document.querySelector("[class*=emojiButton]").click();const t=document.querySelector("[role=textbox]");t.dispatchEvent(new InputEvent("beforeinput",{data:getStickerLink(e),inputType:"insertText"})),t.dispatchEvent(new FocusEvent("focusin"))},disabledSticker.classList.forEach((function(e){e.startsWith("stickerUnsendable")&&disabledSticker.classList.remove(e)}))),e.onmouseup=function(t){3===t.which&&navigator.clipboard.writeText(getStickerLink(e))}}))};document.onclick=function(){try{addEmojiCopy(),document.querySelector("[data-ref-id^=emoji-picker-grid]").querySelector("[class^=scroller]").onscroll=addEmojiCopy;const e=document.querySelector("#emoji-picker-tab-panel");e.onmousemove=addEmojiCopy,e.onkeyup=addEmojiCopy}catch(e){}setTimeout(function(){try{addStickerCopy(),document.querySelector("[data-ref-id^=sticker-picker-grid]").querySelector("[class^=scroller]").onscroll=addStickerCopy;const e=document.querySelector("#sticker-picker-tab-panel");e.onmousemove=addStickerCopy,e.onkeyup=addStickerCopy}catch(e){}},200);};})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment