东京奥运会 跳过CCTV 1/5/5+ 等频道直播广告 自动调整清晰度 显示实时奖牌数、赛程、新闻

跳过CCTV5/5+直播广告

// ==UserScript==
// @name         东京奥运会 跳过CCTV 1/5/5+ 等频道直播广告 自动调整清晰度 显示实时奖牌数、赛程、新闻
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  跳过CCTV5/5+直播广告
// @author       OUSC
// @match        https://tv.cctv.com/live/*
// @grant        none
// @icon         http://tv.cctv.com/favicon.ico
// ==/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);
    let iframe = document.createElement('iframe');
    iframe.setAttribute("src", "https://tiyu.baidu.com/tokyoly/home/tab/%E5%A5%96%E7%89%8C%E6%A6%9C");
    iframe.style.cssText = "width: 320px;height: calc(80% - 30px);border: none;display: none;border: 0;position: fixed;right: 0;top: calc(20% + 30px);z-index: 100; background: #3b82eb;";

    document.body.appendChild(iframe);

    let medalButton = document.createElement('div');
    medalButton.style.cssText= "width: 50px;height: 30px; background: #3b82eb;position: fixed;right: 0;top: 20%;z-index: 100;text-align: center;line-height: 30px;color: #FFF;font-weight: bolder;cursor: pointer";
    medalButton.innerHTML = "🏅️奖牌";
    medalButton.onclick = function(){
        if(iframe.style.display == 'none') {
            iframe.setAttribute("src", "");
            setTimeout(()=>{iframe.setAttribute("src", "https://tiyu.baidu.com/tokyoly/home/tab/%E5%A5%96%E7%89%8C%E6%A6%9C")}, 50);
            iframe.style.display = 'block';
            medalButton.innerHTML = "🏅️隐藏";
        }
        else {
            iframe.style.display = 'none';
            medalButton.innerHTML = "🏅️奖牌";
        }
    }
    document.body.appendChild(medalButton);
})();

function showToast(msg, duration){
    duration = isNaN(duration) ? 3000 : duration;
    let 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);
}