Greasy Fork

Greasy Fork is available in English.

多瑙影院去广告 & 增强

多瑙网站视频与网站广告去除,以及其他增强功能。

当前为 2017-09-16 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         多瑙影院去广告 & 增强
// @namespace    moe.jixun.dn-noad
// @version      1.6
// @description  多瑙网站视频与网站广告去除,以及其他增强功能。
// @author       Jixun Moe<https://jixun.moe/>
// @include      http://*.dnvod.eu/*
// @include      https://*.dnvod.eu/*
// @include      http://*.dnvod.tv/*
// @include      https://*.dnvod.tv/*
// @include      http://*.duonao.tv/*
// @include      https://*.duonao.tv/*
// @grant        none
// @compatible   Firefox  Grease Monkey
// @compatible   Chrome   Tamper Monkey
// @compatible   Opera    Violent Monkey
// @run-at       document-start
// ==/UserScript==

const ads = `#msg_winw, .clickbg, .r-gg, #box1, .bfq-r,
[class^="ggw-"], .tgg, #myaudient2, #z, #a2,
.footerwhole, .gg, .custom-contaienr`;

const w = window;

const each = Array.prototype.forEach;

function remove (el) {
    if (el && el.parentNode) el.parentNode.removeChild(el);
}

function playNextEp () {
    let query = location.search.replace(/&.+/, '');
    let currentEp = document.querySelector('.bfan-n>a[href*="' + query + '"]');
    if (!currentEp) return ; // 未找到当前播放剧集

    let nextEp = currentEp.parentNode.parentNode.nextElementSibling;
    if (!nextEp) return ; // 未找到下一播放剧集

    nextEp = nextEp.querySelector('a');
    if (nextEp) nextEp.click(); // 切换到下一剧集
}

function removeAd() {
    var counter = 100;
    function skipAds() {
        console.info('发送跳过广告事件...');
        document.body.dispatchEvent(new CustomEvent('filterAds'));
    }

    function waitForAds() {
        if (window.loadedHandler) {
            let h = window.loadedHandler;
            window.loadedHandler = function () {
                h();
                setTimeout(skipAds, 50);
            };
            setTimeout(skipAds, 50);
        } else if (counter --> 0) {
            setTimeout(waitForAds, 200);
        } else {
            console.warn('节点获取失败;跳过。');
        }
    }
    waitForAds();
}

function removePlayerLogo () {
    // 改成内置水印也是挺恶心的。
    let ckstyle = w.ckstyle();
    ckstyle.logo = 'null';
    ckstyle.advmarquee = '';
    w.ckstyle = function () { return ckstyle; };
}

addEventListener('DOMContentLoaded', function() {
    'use strict';

    // 去广告与播放器调整
    var style = document.createElement('style');
    style.textContent = `
${ads} { display: none !important; }
.bfq { background: black; }
.bfq-l { width: calc(100% - 20px); }
#video > #a1 { margin: auto; text-align: center; }
`;
    document.head.appendChild(style);

    // 删除广告元素
    each.call(document.querySelectorAll(ads), remove);

    // 检测是否需要移除播放器 Logo
    if (w.ckstyle) {
        console.info('移除 Logo');
        try {
            removePlayerLogo();
        } catch (err) {
            console.info('移除 Logo 失败: ', err);
        }
    }

    // 检测是否需要实现播放下一集功能
    if (w.playerstop) {
        console.info('注册下一集事件成功。');
        window.playerstop = playNextEp;
    }

    if (document.getElementsByClassName('bfq').length > 0) {
        removeAd();
    }
});