Discord Web Ultra Performance Optimizer

Discord web için tüm ağır DOM, animasyon ve eventleri optimize ederek CPU ve RAM kullanımını minimize eder

当前为 2025-08-30 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Discord Web Ultra Performance Optimizer
// @namespace    http://tampermonkey.net/
// @version      2.0.0
// @description  Discord web için tüm ağır DOM, animasyon ve eventleri optimize ederek CPU ve RAM kullanımını minimize eder
// @license      MIT
// @author       Sefa AVAN
// @match        https://discord.com/*
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // ---------- 1) Animasyonları ve transition'ları kapat ----------
    const style = document.createElement('style');
    style.textContent = `
        * { transition: none !important; animation: none !important; }
        img.emoji { image-rendering: pixelated; }
    `;
    document.head.appendChild(style);

    // ---------- 2) Event throttling ----------
    const throttleMs = 50;
    const last = {};
    ['mousemove', 'pointermove', 'scroll', 'resize'].forEach(type => {
        window.addEventListener(type, e => {
            const now = performance.now();
            if(last[type] && now - last[type] < throttleMs){
                e.stopImmediatePropagation();
                e.stopPropagation();
                return;
            }
            last[type] = now;
        }, true);
    });

    // ---------- 3) Lazy-load ağır DOM öğeleri ----------
    function lazyLoadElements(selector){
        document.querySelectorAll(selector).forEach(el => {
            if(!el.dataset.lazy){
                el.dataset.lazy = '1';
                el.style.display = 'none';
                const obs = new IntersectionObserver(entries => {
                    if(entries[0].isIntersecting){
                        el.style.display = '';
                        obs.disconnect();
                    }
                }, { rootMargin: '2000px' });
                obs.observe(el);
            }
        });
    }

    function applyLazyLoad(){
        lazyLoadElements('.emoji-picker, .gift-preview, .activity-feed');
    }

    // ---------- 4) Arka plan sekmede GIF ve videoları durdur ----------
    function manageBackgroundMedia(){
        document.querySelectorAll('img[src$=".gif"], video').forEach(el => {
            if(document.hidden) el.pause ? el.pause() : el.style.display = 'none';
            else el.play ? el.play() : el.style.display = '';
        });
    }

    document.addEventListener('visibilitychange', manageBackgroundMedia);

    // ---------- 5) DOM cleanup: eski mesajlar ----------
    function cleanupOldMessages(){
        const messages = document.querySelectorAll('[id^="message-"]');
        if(messages.length > 50){
            for(let i = 0; i < messages.length - 50; i++){
                messages[i].remove();
            }
        }
    }
    setInterval(cleanupOldMessages, 10000); // her 10 saniyede bir

    // ---------- 6) SPA navigasyonları için yeniden uygula ----------
    const reapplyAll = () => {
        applyLazyLoad();
        manageBackgroundMedia();
        cleanupOldMessages();
    };

    document.addEventListener('DOMContentLoaded', reapplyAll);
    window.addEventListener('yt-navigate-finish', reapplyAll); // SPA navigasyonları için
    window.addEventListener('popstate', reapplyAll);

})();