SilentBalance

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         SilentBalance
// @namespace    http://tampermonkey.net/
// @version      1.0
// @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="24" height="24" viewBox="0 0 24 24">
<path fill="rgb(148,148,148)" d="M11.025 21v-2.15q-1.325-.3-2.287-1.15t-1.413-2.4l1.85-.75q.375 1.2 1.113 1.825t1.937.625q1.025 0 1.738-.462t.712-1.438q0-.875-.55-1.387t-2.55-1.163q-2.15-.675-2.95-1.612t-.8-2.288q0-1.625 1.05-2.525t2.15-1.025V3h2v2.1q1.25.2 2.063.913t1.187 1.737l-1.85.8q-.3-.8-.85-1.2t-1.5-.4q-1.1 0-1.675.488T9.825 8.65q0 .825.75 1.3t2.6 1q1.725.5 2.613 1.588t.887 2.512q0 1.775-1.05 2.7t-2.6 1.15V21z"/>
</svg>`;

    const ICON_OFF = `
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<path fill="rgb(148,148,148)" d="M14.35 8.55q-.3-.75-.887-1.175T12.05 6.95q-.45 0-.875.125t-.775.475L8.95 6.1q.35-.35.95-.638T11 5.1V3h2v2.05q1.125.225 1.975.913T16.25 7.75zM19.8 22.6L15.2 18q-.375.375-1.025.613T13 18.9V21h-2v-2.15q-1.4-.35-2.337-1.275T7.3 15.25l2-.8q.3 1.05 1.013 1.8T12.2 17q.45 0 .825-.112t.725-.338L1.4 4.2l1.4-1.4l18.4 18.4z"/>
</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);
    };

    const uiTimer = setInterval(() => {

        const controls = document.querySelector('.conversation-controls');
        const soundBtn = document.querySelector('#SoundNotificationSwitcher');

        if (!controls || !soundBtn) return;

        if (document.querySelector('#BalanceMuteSwitcher')) {
            clearInterval(uiTimer);
            return;
        }

        const btn = document.createElement('div');
        btn.id = 'BalanceMuteSwitcher';
        btn.className = 'f_r conversationControl Tooltip OverlayTrigger';
        btn.style.cursor = 'pointer';

        const icon = document.createElement('span');
        icon.style.display = 'flex';
        icon.style.alignItems = 'center';
        icon.style.height = '18px';
        icon.style.lineHeight = '18px';
        icon.style.transform = 'translateY(-1px)';

        btn.appendChild(icon);

        function render() {
            icon.innerHTML = enabled ? ICON_OFF : ICON_ON;

            btn.setAttribute(
                'title',
                enabled
                    ? 'Звук перевода отключён'
                    : 'Звук перевода включён'
            );
        }

        render();

        btn.onclick = () => {
            enabled = !enabled;
            localStorage.setItem(STORAGE_KEY, enabled ? '1' : '0');
            render();
        };

        soundBtn.after(btn);

        clearInterval(uiTimer);

    }, 300);

})();