Greasy Fork

Greasy Fork is available in English.

Super Duolingo Ad Blocker

Block ads and unwanted promotional content on Duolingo, including full-browser videos and dynamically named ad classes, while preserving essential lesson content.

当前为 2024-07-28 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Super Duolingo Ad Blocker
// @version      0.3
// @description  Block ads and unwanted promotional content on Duolingo, including full-browser videos and dynamically named ad classes, while preserving essential lesson content.
// @author       Zinovia
// @match        https://www.duolingo.com/*
// @grant        none
// @namespace http://greasyfork.icu/users/1340999
// ==/UserScript==

(function() {
    'use strict';

    // Function to inject CSS into the document
    function addStyles(css) {
        const style = document.createElement('style');
        style.type = 'text/css';
        style.textContent = css;
        document.head.appendChild(style);
    }

    // CSS to hide specific promotional and ad content
    const styles = `
        /* General video ad elements */
        video {
            display: none !important;
            volume: 0;
        }

        /* Specific divs associated with ads and promotions, conditional on not being essential content */
        div[data-test="purchase-step-active"],
        div._3D_HB,
        div._16rRh, 
        div._1tzFd {
            display: none !important;
        }
    `;

    // Inject styles into the document
    addStyles(styles);

    // Function to dynamically hide elements and mute videos
    function hideElementsAndMuteVideos() {
        const selectors = [
            'video',
            'div[data-test="purchase-step-active"]',
            'div._3D_HB',
            'div._16rRh',
            'div._1tzFd',
            'div.MGk8p',
            'div._3ywWe',
            'div._1145W',
            'div._1Qh5D _36g4N _2YF0P uapW2',
        ];

        selectors.forEach(selector => {
            document.querySelectorAll(selector).forEach(element => {
                if (!element.closest('.learning-path')) { // Ensures that elements within the learning path are not hidden
                    element.style.display = 'none';
                }
            });
        });

        // Mute and pause videos to prevent audio play
        document.querySelectorAll('video').forEach(video => {
            video.volume = 0;
            video.pause();
        });
    }

    // Run function initially to hide elements and mute videos
    hideElementsAndMuteVideos();

    // Observe DOM changes and apply modifications as necessary
    const observer = new MutationObserver(hideElementsAndMuteVideos);
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    console.log('Super Duolingo Ad Blocker initialized.');
})();