Eternity Tower User Mute

User muting for Eternity Tower. Must refresh after altering list.

  1. // ==UserScript==
  2. // @name Eternity Tower User Mute
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description User muting for Eternity Tower. Must refresh after altering list.
  6. // @author Aes Sedai
  7. // @match http*://*.eternitytower.net/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. window.usermute = {};
  15. window.usermute.users = JSON.parse(localStorage.getItem('usermute_users')) || [];
  16.  
  17. var muteInterval = setInterval(function() {
  18. if (document.querySelector("#navbarSupportedContent > form > ul") !== null) {
  19. var shopNav = document.querySelector("#navbarSupportedContent > form > ul");
  20. var muteButtonLi = document.createElement("li");
  21. muteButtonLi.className = "nav-item";
  22. var muteButton = document.createElement("a");
  23. muteButton.className = "nav-link";
  24. muteButton.href = "#";
  25. muteButton.id = "muteButton";
  26. muteButton.innerHTML = "Muted Users";
  27. muteButton.onclick = function() {
  28. var users = prompt("Please enter a lowercased, comma-separated list of users", window.usermute.users.join(','));
  29. if (users !== null) {
  30. window.usermute.users = users.split(',');
  31. console.log("usernames: ", window.usermute.users);
  32. }
  33. };
  34. muteButtonLi.appendChild(muteButton);
  35. shopNav.insertBefore(muteButtonLi, shopNav.childNodes[0]);
  36. clearInterval(muteInterval); // here muteInterval is undefined, but when we call this function it will be defined in this context
  37. }
  38. }, 100);
  39.  
  40. Meteor.connection._stream.on('message', function(sMeteorRawData){
  41. try {
  42. var oMeteorData = JSON.parse(sMeteorRawData);
  43. if (oMeteorData.collection == "simpleChats") {
  44. if (window.usermute.users.indexOf(oMeteorData.fields.username) > -1) {
  45. var interval = setInterval(function() {
  46. if (document.getElementById(oMeteorData.id) !== null) {
  47. var elem = document.getElementById(oMeteorData.id);
  48. elem.setAttribute("style", "display:none;");
  49. clearInterval(interval); // here interval is undefined, but when we call this function it will be defined in this context
  50. }
  51. }, 50);
  52. }
  53. }
  54. }
  55. catch (err) { }
  56. });
  57.  
  58. window.onbeforeunload = function() {
  59. localStorage.setItem('usermute_users', JSON.stringify(window.usermute.users));
  60. };
  61. })();