Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. /**
  2. * Ping your friend any number of emojis automatically
  3. * in the slack web application
  4. *
  5. * This script is only for having fun. not for other purposes :)
  6. *
  7. * Working on optimizing it.
  8. */
  9.  
  10. // Variable Declaration
  11. var expectedNumberOfPings = 20; // Set the number of Emojis, you want to ping
  12. var pingTimeoutHolder = [];
  13.  
  14. /**
  15. * pingEmojis
  16. * @description [Pings the Emojis]
  17. * @return {Undefined}
  18. */
  19. function pingEmojis() {
  20. // Variable Declarations
  21. var numberOfPings = 0;
  22. var sec = 10;
  23. var inc = 50;
  24. var batchLimit = 10;
  25. var itemsInBatch = 0;
  26.  
  27. // Goes through the emoji global object which contains all the
  28. // data about the emoji's in slack web application
  29. for (var key in emoji.data) {
  30. // Holds the current emoji data
  31. var data = emoji.data[key];
  32. // Gets the current emoji's value
  33. var currentEmoji = typeof data[3] != "undefined" && typeof data[3][0] == "string" ? data[3][0] : undefined;
  34.  
  35. // Checks for the validity of it
  36. if (currentEmoji) {
  37. // Holds back the timeout objects, so that it can be used
  38. // in case for clearing it
  39. pingTimeoutHolder.push(setTimeout(function(currentEmoji) {
  40. // Sets the text in the message box to empty
  41. $('[aria-label^="Message "]>p').text(" ");
  42. // Sets the text in the message box to emoji's value covered by colon
  43. $('[aria-label^="Message "]>p').text(":" + currentEmoji + ":");
  44. // Submits the Message form
  45. setTimeout(function() {
  46. $("#msg_form").submit();
  47. }, 0);
  48. }, sec, currentEmoji));
  49. // Checks the expected pings to be unlimited or not
  50. if (expectedNumberOfPings !== Infinity) {
  51. // Increments the ping count
  52. numberOfPings++;
  53. // Exits the loop when the number of pings reaches the expected count
  54. if (expectedNumberOfPings === 0 || numberOfPings === expectedNumberOfPings) {
  55. break;
  56. }
  57. }
  58. // Increments the timeout, so that the next ping will not get overlapped
  59. // with the previous one
  60. sec += inc;
  61. }
  62. }
  63. }
  64.  
  65. /**
  66. * stopPinging
  67. * @description [Cancels the Pings which not yet executed]
  68. * @return {Undefined}
  69. */
  70. function stopPinging() {
  71. // Loops through the timeout and clears it
  72. pingTimeoutHolder.map(function(pingTimeout) {
  73. clearTimeout(pingTimeout);
  74. });
  75. // Resets the holder
  76. pingTimeoutHolder = [];
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement