Greasy Fork

Greasy Fork is available in English.

东京奥运会 跳过 CCTV 5/5+直播广告

跳过CCTV5/5+直播广告

当前为 2021-07-30 提交的版本,查看 最新版本

// ==UserScript==
// @name         东京奥运会 跳过 CCTV 5/5+直播广告
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  跳过CCTV5/5+直播广告
// @author       OUSC
// @match        https://tv.cctv.com/live/*
// @grant        none
// ==/UserScript==

let definition = "720"; //清晰度设置:null/720/540/480/360

(function() {
    'use strict';
    let interval = setInterval(()=>{
        try{
            let videoElement = document.getElementById("h5player_player");
            if(videoElement && !isNaN(videoElement.currentTime + videoElement.duration)) videoElement.currentTime = videoElement.currentTime + videoElement.duration;
            let tag = document.getElementById("resolution_item_" + definition +"_player");
            if(tag && !!definition) tag.click();
            if(videoElement && tag) {
                showToast("已为您跳过广告并切换至" + definition + 'P清晰度',3000);
                clearInterval(interval);
            }
        } catch(e){
            console.log(e)
        }
    }, 100)
    })();

function showToast(msg, duration){
    duration = isNaN(duration) ? 3000 : duration;
    var m = document.createElement('div');
    m.innerHTML = msg;
    m.style.cssText="width:240px; height: 30px; background:rgba(255, 255, 255, 0.5);color:#fff; line-height:30px; text-align:center; border-radius:4px; position:fixed; bottom:50px; left:0;right: 0;margin: auto; z-index:999999;";
    document.body.appendChild(m);
    setTimeout(function() {
        var d = 0.5;
        m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
        m.style.opacity = '0';
        setTimeout(function() { document.body.removeChild(m) }, d * 1000);
    }, duration);
}