ROBLOX Group Invite Archiver

Filter out spammy messages about group invites.

  1. // ==UserScript==
  2. // @name ROBLOX Group Invite Archiver
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.11
  5. // @description Filter out spammy messages about group invites.
  6. // @author samfun123
  7. // @match *.roblox.com/My/Messages
  8. // @noframes
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. $.fn.exists = function () {
  14. return this.length !== 0;
  15. };
  16.  
  17. function getCookie(c_name)
  18. {
  19. if (document.cookie.length > 0)
  20. {
  21. c_start = document.cookie.indexOf(c_name + "=");
  22. if (c_start != -1)
  23. {
  24. c_start = c_start + c_name.length + 1;
  25. c_end = document.cookie.indexOf(";", c_start);
  26. if (c_end == -1) c_end = document.cookie.length;
  27. return unescape(document.cookie.substring(c_start,c_end));
  28. }
  29. }
  30. return "";
  31. }
  32.  
  33. function getMessages(page, callback) {
  34. $.ajax({
  35. url: "https://www.roblox.com/messages/api/get-messages?messageTab=0&pageNumber=" + page + "&pageSize=20",
  36. success: callback
  37. });
  38. }
  39.  
  40. function archiveInvites() {
  41. getMessages(0, function(total) {
  42. var invites = [];
  43. var counted = 0;
  44.  
  45. for (n = 0; n < total.TotalPages; n++) {
  46. getMessages(n, function(messages) {
  47. for (i = 0; i < messages.Collection.length; i++) {
  48. var message = messages.Collection[i];
  49. var matches = message.Body.match(/\.roblox\.com\/My\/Groups\.aspx\?gid=\d+/);
  50. if (matches) {
  51. if (matches.length > 0) {
  52. invites.push(message.Id);
  53. }
  54. }
  55. }
  56.  
  57. counted++;
  58. if (counted == total.TotalPages) {
  59. if (invites.length > 0) {
  60. console.log("Archived " + invites.length + " potential group invites.");
  61. $.ajax({
  62. url: "https://www.roblox.com/messages/api/archive-messages",
  63. method: "POST",
  64. headers: { "X-CSRFToken": getCookie("csrftoken") },
  65. data: {
  66. "messageIds": invites
  67. },
  68. success: function() {
  69. window.location.reload();
  70. }
  71. });
  72. }
  73. }
  74. });
  75. }
  76. });
  77. }
  78.  
  79. var checker = new MutationObserver(function() {
  80. var archive = $('.roblox-archiveButton');
  81. var custom = $('.custom-archiveInvites');
  82.  
  83. if (archive.exists() && !custom.exists()) {
  84. $('<button class="custom-archiveInvites roblox-message-large-btn btn-control">Archive Group Invites</button>').insertBefore(archive).click(archiveInvites);
  85. }
  86. });
  87.  
  88. checker.observe(document, {childList:true, subtree: true});
  89. })();