IYF Ad Blocker

Filter ads on www.iyf.com

目前為 2025-08-19 提交的版本,檢視 最新版本

// ==UserScript==
// @name         IYF Ad Blocker
// @name:zh-CN   IYF Ad Blocker on www.iyf.com
// @namespace    http://tampermonkey.net/
// @version      0.1.0
// @description  Filter ads on www.iyf.com
// @description:zh-CN  过滤广告 on www.iyf.com
// @author       Dylan Zhang
// @include      https://www.iyf.tv/**
// @icon         https://www.google.com/s2/favicons?sz=64&domain=iyf.tv
// @license      MIT
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    /* utilities */
    function $(selector) {
        return document.querySelector(selector)
    }

    function getCurrentPath() {
        const path = unsafeWindow.location.pathname.split('/')[1]
        return path ? `/${path}` : ''
    }

    function addEvent(el, type, handler) {
        if (typeof el === 'string') el = $(el)
        el.addEventListener(type, handler, false)
    }

    function nextTick(fn) {
        setTimeout(fn)
    }

    /* home page */
    function filterHomePage() {
        GM_addStyle(`
            app-recommended-news:nth-of-type(2),
            app-classified-top-videos:nth-of-type(1) > app-home-collection,
            div:has(> app-discovery-in-home),
            .new-list {
               display: none!important;
            }
        `)
    }

    /* play/watch page */
    function filterPlayPage() {
        GM_addStyle(`
            div.ps > div.bl,
            vg-pause-f,
            .caption {
               display: none!important;
            }
        `)

        nextTick(() => {
            $(`app-video-user-data-bar + div`).remove()
        })

        filterPlayer()
    }

    function filterPlayer() {
        let timer
        const timeout = 5000

        let playerEl
        let pauseOverlayEl

        init()

        function init() {
            timer = setInterval(findPlayer, 1000)
            setTimeout(clear, timeout)
        }

        function findPlayer() {
            playerEl = $('#video_player')
            if (playerEl) {
                clearInterval(timer)
                setPlayer()
            }
        }

        function clear(){
            if (!playerEl) {
                clearInterval(timer)
            }
        }

        function setPlayer(){
            addEvent(playerEl, 'pause', onPause)
        }

        function onPause(){
            pauseOverlayEl = $('.publicbox')
            if (pauseOverlayEl) {
                pauseOverlayEl.remove()
                pauseOverlayEl = null
                if (playerEl.paused) {
                    playerEl.play()
                }
            }
        }
    }

    // main
    function main() {
        const path = getCurrentPath()
        console.log('------', path)
        switch (path) {
            case '':
                filterHomePage()
                break
            case '/watch':
            case '/play':
                filterPlayPage()
                break
        }
    }

    main()
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址