LZTConversationsMute

Отключаем уведомления с диалогов

  1. // ==UserScript==
  2. // @name LZTConversationsMute
  3. // @namespace Melonium/LZT
  4. // @version 2.0
  5. // @description Отключаем уведомления с диалогов
  6. // @author MeloniuM
  7. // @license MIT
  8. // @match *://zelenka.guru/*
  9. // @match *://lzt.market/*
  10. // @match *://lolz.guru/*
  11. // @match *://lolz.live/*
  12. // @icon https://www.google.com/s2/favicons?sz=64&domain=zelenka.guru
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16.  
  17. (function() {
  18. 'use strict';
  19. var mutedList = localStorage.getItem('conversationsMuted')? localStorage.getItem('conversationsMuted').split(',').map(Number) : [];
  20. //Стильно, модно, молодёжно
  21. $("<style>").prop("type", "text/css").html(".conversationItem .avatar .conversationMute{position: absolute; background-color: rgb(39, 39, 39); border-radius: 50%; border: 1px solid rgb(17 17 17); text-align: center; line-height: 16px; top: 3px; left: 34px; height: 16px; width: 16px; display: inline-block; z-index: 1}").appendTo("head");
  22. const lang = XenForo.visitor.language_id - 1;
  23. const phrases = {
  24. 'mute': (lang? 'Откл. уведомления': 'Mute alerts'),
  25. 'unmute': (lang? 'Вкл. уведомления': 'Unmute alerts')
  26. };
  27.  
  28. XenForo.conversationMuteButton = function($button) {
  29. $button.on('click', function(e){
  30. e.preventDefault();
  31. let $target = $(e.target);
  32. let id = $target.data('id');
  33. let isMuted = muteToggle(id, $('#conversation-' + id + ' .avatar .conversationMute'));
  34. $target.text(phrases[(isMuted? 'unmute': 'mute')]);
  35. })
  36. }
  37. XenForo.register(".conversationMuteButton", "XenForo.conversationMuteButton");
  38.  
  39. function addIcon($target){
  40. let show = true;
  41. let id = $target.attr('data-cid');
  42. if (!mutedList.includes(Number(id))) show = false;
  43. //выбор иконки
  44. const i = $(`<i class="fa fa-volume-mute conversationMute"></i>`);
  45. if (!show) i.hide();
  46.  
  47. i.on('click', function(event) {//быстрый размут
  48. event.preventDefault();
  49. event.stopPropagation();
  50.  
  51. let id = $(event.target).closest('.conversationItem').attr('data-cid');
  52. let isMuted = muteToggle(id, $(event.target));
  53. //меняем текст на кнопке в менюшке
  54. $('.conversationMuteButton[data-id="' + id + '"]').text(phrases[(isMuted? 'unmute': 'mute')]);
  55. });
  56.  
  57. if (!$target.find('.avatar .conversationMute').length) $target.find('.avatar').append(i);
  58. }
  59.  
  60. function muteToggle(id, icon){
  61. let muted = true;
  62. mutedList = localStorage.getItem('conversationsMuted')? localStorage.getItem('conversationsMuted').split(',').map(Number) : [];
  63. if (!mutedList.includes(Number(id))){
  64. //отключаем уведы
  65. mutedList.push(Number(id))
  66. icon.show();
  67. }else{
  68. //включаем уведы
  69. mutedList.splice(mutedList.indexOf(Number(id)),1)
  70. icon.hide();
  71. muted = false;
  72. }
  73. localStorage.setItem('conversationsMuted', mutedList.join(','));
  74. return muted;// значение после изменений
  75. }
  76.  
  77. if (window.location.pathname.startsWith('/conversations')){
  78. $("<style>").prop("type", "text/css").html(".conversationItem .avatar.fa.fa-volume-mute::before {position: absolute; background-color: rgb(39, 39, 39); border-radius: 50%; border: 1px solid rgb(17 17 17); text-align: center; line-height: 16px; top: 3px; left: 34px; height: 16px; width: 16px; display: inline-block; z-index: 1}").appendTo("head");
  79.  
  80. //при смене позиции диалога в списке 'XenForoActivate' не вызывается, поэтому используем 'DOMNodeInserted'
  81. $(document).on('DOMNodeInserted', '.conversationItem:not(:has(.conversationMute))', function(e){
  82. const $target = $(e.target);
  83. addIcon($(e.target));
  84. });
  85.  
  86. $(document).bind('PopupMenuShow', function(e){
  87. let $menu = e.$menu
  88. let $context = $($menu.context);
  89. if ($context.is('.RecipientsPopup') || !$context.closest('.membersAndActions').length) return;
  90. if ($menu.find('.conversationMuteButton').length) return;
  91. mutedList = localStorage.getItem('conversationsMuted')? localStorage.getItem('conversationsMuted').split(',').map(Number) : [];
  92. let phrase = phrases[(mutedList.includes(Im.conversationId)? 'unmute': 'mute')];
  93. $menu.find(".secondaryContent, .blockLinksList").append('<a class="item control conversationMuteButton MenuCloser" data-id="' + Im.conversationId + '">' + phrase + '</a>').xfActivate();
  94. });
  95.  
  96. $('#ConversationListItems').find('.conversationItem:not(:has(.conversationMute))').each(function(index){
  97. addIcon($(this));
  98. });
  99. }else{
  100.  
  101. $(window).on('load', function(){
  102. let s;
  103. const m = (s = window).Im || (s.Im = {});
  104.  
  105. const notification = $('html').data('Im.Notification');
  106. if (!notification) return;
  107. notification.displayNotification_old = notification.displayNotification;
  108. notification.displayNotification = (data) => {
  109. if (mutedList.includes(data.conversation_id) && !location.pathname.startsWith('/conversations')){
  110. notification.handledNotifications.add(data.message.message_id);
  111. if (!m.newMessageCache[data.conversationId]) {
  112. m.newMessageCache.push(data.conversationId);
  113. }
  114. var popup = $("#ConversationsMenu.Menu").data("XenForo.PopupMenu");
  115. if (popup) popup.reload();//Обновление счетчика сообщений в меню в шапке сайта
  116. return;
  117. }
  118. return notification.displayNotification_old(data);
  119. }
  120. });
  121. };
  122. //синхронизация между вкладками
  123. $(window).bind('storage', function (e) {
  124. if(e.originalEvent.key !== 'conversationsMuted') return;
  125. mutedList = e.originalEvent.newValue;
  126.  
  127. if (window.location.pathname.startsWith('/conversations')){
  128. let [newValue, oldValue] = [e.originalEvent.newValue.split(','), e.originalEvent.oldValue.split(',')];
  129. let del = true;//айди удалился
  130. let arrA, arrB;
  131. if (newValue.length > oldValue.length){
  132. del = false;//добавился новый айди
  133. //если новое значение больше, фильтровать будем
  134. arrA = newValue;
  135. arrB = oldValue;
  136. }else{
  137. //если новое значение больше, значит айди удалился
  138. arrA = oldValue;
  139. arrB = newValue;
  140. }
  141. //получим элементы из массива A, которых нет в массиве B.
  142. let ids = arrA.filter(x => !arrB.includes(x));
  143. //в теории их может быть больше 1
  144. ids.forEach((id) => {
  145. $('.conversationMuteButton[data-id="' + id + '"]').text(phrases[(!del? 'unmute': 'mute')]);//смена текста на кнопке в меню
  146. $('#conversation-' + id + ' .avatar .conversationMute')[!del? 'show': 'hide']();//скрытие/показ иконки на аве
  147. })
  148. }
  149. });
  150. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址