Last active
July 22, 2023 04:43
-
-
Save monzou/ca7e4ac928ff46a40cb7bb7fb0940f23 to your computer and use it in GitHub Desktop.
Add random emojis in Slack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const emojis = [ | |
"clapping_fast", | |
"clapping_very_fast", | |
"kami", | |
"saikou", | |
"_waiwai", | |
"tada", | |
"beer-1", | |
"sparkle", | |
"heart", | |
"kinako_woot", | |
"pikachu_dancing", | |
"bling", | |
"blob-hearts", | |
"clap", | |
"blob_cheer", | |
"rocket", | |
"yoi", | |
"laughing", | |
"raised_hands", | |
"kirby_pan", | |
"cherry_blossom", | |
"gogogogo", | |
"nyangif16", | |
"sunshine", | |
"炎_fire", | |
]; | |
const select = (array, limit) => { | |
for (let i = array.length - 1; i > 0; i--) { | |
const j = Math.floor(Math.random() * (i + 1)); | |
[array[i], array[j]] = [array[j], array[i]]; | |
} | |
return array.slice(0, limit); | |
}; | |
const addReaction = ($e, emoji) => { | |
$e.value = emoji; | |
$e.simulated = true; | |
if ($e._valueTracker) { | |
$e._valueTracker.setValue(""); | |
} | |
const search = new Event("input", { bubbles: true }); | |
$e.dispatchEvent(search); | |
const $i = document.getElementsByClassName("p-emoji_picker__list_item")[0]; | |
const click = new MouseEvent("click", { | |
bubbles: true, | |
cancelable: true, | |
view: window, | |
shiftKey: true, | |
}); | |
$i.dispatchEvent(click); | |
}; | |
const addReactionWithDelay = ($e, emoji) => { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
addReaction($e, emoji); | |
resolve(); | |
}, 300); | |
}); | |
}; | |
document.addEventListener("dblclick", (event) => { | |
var $e = document.elementFromPoint(event.clientX, event.clientY); | |
if ($e && $e.hasAttribute("data-input-metric-boundary")) { | |
if ($e.getAttribute("data-input-metric-boundary") === "emoji_picker") { | |
(async function () { | |
for (let emoji of select(emojis, 10)) { | |
await addReactionWithDelay($e, emoji); | |
} | |
})(); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment