SilentBalance

Отключает звук перевода денег (balance.mp3), но оставляет звук сообщений

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey to install this script.

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         SilentBalance
// @namespace    http://tampermonkey.net/
// @version      1.1
// @author       Welhord
// @description  Отключает звук перевода денег (balance.mp3), но оставляет звук сообщений
// @match        https://lolz.live/*
// @match        https://zelenka.guru/*
// @match        https://lzt.market/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const STORAGE_KEY = 'lzt_balance_mute';
    let enabled = localStorage.getItem(STORAGE_KEY) !== '0';

    const ICON_ON = `
<svg xmlns="http://www.w3.org/2000/svg" width="10" height="18" viewBox="0 0 10 18" fill="rgb(148,148,148)"><g clip-path="url(#clip0_287_850)">
<path d="M3.99999 18V15.85C3.11666 15.65 2.35432 15.2667 1.71299 14.7C1.07165 14.1333 0.600655 13.3333 0.299988 12.3L2.14999 11.55C2.39999 12.35 2.77099 12.9583 3.26299 13.375C3.75499 13.7917 4.40066 14 5.19999 14C5.88332 14 6.46266 13.846 6.93799 13.538C7.41332 13.23 7.65066 12.7507 7.64999 12.1C7.64999 11.5167 7.46666 11.0543 7.09999 10.713C6.73332 10.3717 5.88332 9.984 4.54999 9.55C3.11666 9.1 2.13332 8.56267 1.59999 7.938C1.06665 7.31333 0.799988 6.55067 0.799988 5.65C0.799988 4.56667 1.14999 3.725 1.84999 3.125C2.54999 2.525 3.26666 2.18333 3.99999 2.1V0H5.99999V2.1C6.83332 2.23333 7.52099 2.53767 8.06299 3.013C8.60499 3.48833 9.00066 4.06733 9.24999 4.75L7.39999 5.55C7.19999 5.01667 6.91666 4.61667 6.54999 4.35C6.18332 4.08333 5.68332 3.95 5.04999 3.95C4.31666 3.95 3.75832 4.11267 3.37499 4.438C2.99166 4.76333 2.79999 5.16733 2.79999 5.65C2.79999 6.2 3.04999 6.63333 3.54999 6.95C4.04999 7.26667 4.91666 7.6 6.14999 7.95C7.29999 8.28333 8.17099 8.81267 8.76299 9.538C9.35499 10.2633 9.65066 11.1007 9.64999 12.05C9.64999 13.2333 9.29999 14.1333 8.59999 14.75C7.89999 15.3667 7.03332 15.75 5.99999 15.9V18H3.99999Z"/></g><defs>
<clipPath id="clip0_287_850"><rect width="10" height="18"/></clipPath></defs>
</svg>`;

    const ICON_OFF = `
<svg xmlns="http://www.w3.org/2000/svg" width="10" height="18" viewBox="0 0 10 18" fill="rgb(148,148,148)">
<path d="M8.21777 8.96875C8.43025 9.14276 8.62039 9.33262 8.78809 9.53809C9.38 10.2633 9.67543 11.1006 9.6748 12.0498C9.6748 13.2331 9.325 14.1333 8.625 14.75C7.92507 15.3666 7.05858 15.7504 6.02539 15.9004V18H4.02539V15.8496C3.32691 15.6915 2.70537 15.4167 2.1582 15.0293L3.59473 13.5928C4.03893 13.8627 4.58133 13.9999 5.22461 14C5.90788 14 6.48758 13.846 6.96289 13.5381C7.43822 13.2301 7.67547 12.7503 7.6748 12.0996C7.67472 11.5165 7.49158 11.0541 7.125 10.7129C7.03069 10.6251 6.90434 10.5343 6.74609 10.4404L8.21777 8.96875ZM6.02539 2.09961C6.84296 2.23047 7.51951 2.52723 8.05664 2.9873L6.64453 4.4043C6.62149 4.38591 6.59894 4.36688 6.5752 4.34961C6.20857 4.083 5.7084 3.95022 5.0752 3.9502C4.34186 3.9502 3.78372 4.11314 3.40039 4.43848C3.01707 4.76381 2.8252 5.16773 2.8252 5.65039C2.82531 6.2002 3.07531 6.6336 3.5752 6.9502C3.67509 7.01345 3.79077 7.07507 3.91992 7.13965L2.44434 8.62109C2.10457 8.4061 1.83081 8.17946 1.625 7.93848C1.09174 7.3139 0.825272 6.55089 0.825195 5.65039C0.825195 4.56706 1.175 3.725 1.875 3.125C2.575 2.525 3.29206 2.18294 4.02539 2.09961V0H6.02539V2.09961Z"/>
<path d="M0.922601 14.1335L0 13.2002L9.06042 4L10 4.9505L0.922601 14.1335Z"/>
</svg>`;

    const originalPlay = HTMLAudioElement.prototype.play;

    HTMLAudioElement.prototype.play = function () {

        if (
            enabled &&
            this.src &&
            this.src.includes('balance.mp3')
        ) {
            return Promise.resolve();
        }

        return originalPlay.apply(this, arguments);
    };

    XenForo.register('div#Conversations div.conversation-controls', function () {
        const $el = $(this);

        if ($el.find('#BalanceMuteSwitcher').length) return;

        $('<style>').text(`
                #BalanceMuteSwitcher:hover svg {
                   fill: rgb(214, 214, 214);
                }`
        ).appendTo('head');

        const $switcher = $('<div>', {
            id: 'BalanceMuteSwitcher',
            class: 'fl_r conversationControl',
            css: { cursor: 'pointer' }
        });

        const buttons = [
            {
                cls: 'Enable',
                icon: ICON_ON,
                tooltip: 'Выключить звуковые оповещения при получении денежных средств',
                value: true
            },
            {
                cls: 'Disable',
                icon: ICON_OFF,
                tooltip: 'Включить звуковые оповещения при получении денежных средств',
                value: false
            }
        ];

        const createBtn = ({ cls, icon, tooltip, value }) =>
        $(`<span class="${cls} Tooltip" title="" data-cachedtitle="${tooltip}">${icon}</span>`)
        .attr('data-value', value ? '1' : '0');

        const $btns = buttons.map(createBtn);

        $switcher.append($btns);
        $el.append($switcher);

        $switcher.find('.Tooltip').xfActivate();

        function render() {
            $btns.forEach($b => $b.toggle($b.attr('data-value') !== (enabled ? '1' : '0')));
        }

        $switcher.on('click', 'span', function () {
            enabled = $(this).attr('data-value') === '1';
            localStorage.setItem(STORAGE_KEY, enabled ? '1' : '0');
            render();
        });

        render();
    });
})();