Greasy Fork is available in English.
Добавляет кнопку отключения уведомлений из диалога
当前为
// ==UserScript==
// @name LZTConversationsMute
// @namespace Melonium/LZT
// @version 1.5
// @description Добавляет кнопку отключения уведомлений из диалога
// @author MeloniuM
// @license MIT
// @match *://zelenka.guru/*
// @match *://lzt.market/*
// @match *://lolz.guru/*
// @match *://lolz.live/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=zelenka.guru
// @grant none
// ==/UserScript==
(function() {
'use strict';
var muted = localStorage.getItem('conversationsMuted')? localStorage.getItem('conversationsMuted').split(',').map(Number) : [];
function addIcon(item){
let i = document.createElement('i')
if (!(item instanceof HTMLElement)) return;
//выбор иконки
let id = item.closest('.conversationItem').getAttribute('data-cid')
if (!muted.includes(Number(id))){
i.setAttribute('class', 'fa fa-volume conversationMute')
}else{
i.setAttribute('class', 'fa fa-volume-mute conversationMute')
}
i.setAttribute('aria-hidden', 'true')
i.style.marginRight = '5px'
i.style.float = 'right'
i.style.zIndex = 1 //поверх названия диалога, чтобы при клике не открывать диалог
// Настройка обработчика события на кнопке
i.addEventListener('click', function(event) {
// Действие, которое выполняется при нажатии на кнопку
let id = event.target.closest('.conversationItem').getAttribute('data-cid')
muteToggle(id, event.target);
});
// Добавляем кнопку в элемент ConversationListItems
if (!item.querySelector('.title .conversationMute')) item.querySelector('.title').appendChild(i);
}
function muteToggle(id, icon){
let muted = localStorage.getItem('conversationsMuted')? localStorage.getItem('conversationsMuted').split(',').map(Number) : [];
if (!muted.includes(Number(id))){
muted.push(Number(id))
icon.setAttribute('class', 'fa fa-volume-mute conversationMute')
localStorage.setItem('conversationsMuted', muted.join(','))
}else{
muted.splice(muted.indexOf(Number(id)),1)
icon.setAttribute('class', 'fa fa-volume conversationMute')
localStorage.setItem('conversationsMuted', muted.join(','));//удаляем айди беседы
}
}
if (window.location.pathname.startsWith('/conversations')){
var list_ = document.querySelector('#ConversationListItems');
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === "childList") {
for (let item of mutation.addedNodes) {
addIcon(item)
}
}
});
});
observer.observe(list_, {
childList: true
});
var conversationList = document.querySelectorAll('.conversationItem');
conversationList.forEach(function(item) {
// Создаем кнопку
addIcon(item)
});
}else{
Im.Notification.prototype.displayNotification_old = Im.Notification.prototype.displayNotification
Im.Notification.prototype.displayNotification = (data) => {
if (muted.includes(data.conversation_id) && !location.pathname.startsWith('/conversations')){
if (!Im.newMessageCache[data.conversationId]) {
Im.newMessageCache.push(data.conversationId);
}
return;//отключаем уведомление
}
return Im.Notification.prototype.displayNotification_old(data)
}}
})();