Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Ping your friend any number of emojis automatically
- * in the slack web application
- *
- * This script is only for having fun. not for other purposes :)
- *
- * Working on optimizing it.
- */
- // Variable Declaration
- var expectedNumberOfPings = 20; // Set the number of Emojis, you want to ping
- var pingTimeoutHolder = [];
- /**
- * pingEmojis
- * @description [Pings the Emojis]
- * @return {Undefined}
- */
- function pingEmojis() {
- // Variable Declarations
- var numberOfPings = 0;
- var sec = 10;
- var inc = 50;
- var batchLimit = 10;
- var itemsInBatch = 0;
- // Goes through the emoji global object which contains all the
- // data about the emoji's in slack web application
- for (var key in emoji.data) {
- // Holds the current emoji data
- var data = emoji.data[key];
- // Gets the current emoji's value
- var currentEmoji = typeof data[3] != "undefined" && typeof data[3][0] == "string" ? data[3][0] : undefined;
- // Checks for the validity of it
- if (currentEmoji) {
- // Holds back the timeout objects, so that it can be used
- // in case for clearing it
- pingTimeoutHolder.push(setTimeout(function(currentEmoji) {
- // Sets the text in the message box to empty
- $('[aria-label^="Message "]>p').text(" ");
- // Sets the text in the message box to emoji's value covered by colon
- $('[aria-label^="Message "]>p').text(":" + currentEmoji + ":");
- // Submits the Message form
- setTimeout(function() {
- $("#msg_form").submit();
- }, 0);
- }, sec, currentEmoji));
- // Checks the expected pings to be unlimited or not
- if (expectedNumberOfPings !== Infinity) {
- // Increments the ping count
- numberOfPings++;
- // Exits the loop when the number of pings reaches the expected count
- if (expectedNumberOfPings === 0 || numberOfPings === expectedNumberOfPings) {
- break;
- }
- }
- // Increments the timeout, so that the next ping will not get overlapped
- // with the previous one
- sec += inc;
- }
- }
- }
- /**
- * stopPinging
- * @description [Cancels the Pings which not yet executed]
- * @return {Undefined}
- */
- function stopPinging() {
- // Loops through the timeout and clears it
- pingTimeoutHolder.map(function(pingTimeout) {
- clearTimeout(pingTimeout);
- });
- // Resets the holder
- pingTimeoutHolder = [];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement