html制作新闻页面cctv,HTML5 on CCTV

// ==UserScript==

// @name HTML5 on CCTV

// @namespace https://github.com/sffxzzp

// @version 0.18

// @description Replace Flash Player with HTML5 Player on tv.cctv.com

// @author sffxzzp

// @include /^https?://tv.cctv.com/\d*/\d*/\d*/VIDE.*.shtml*/

// @require https://cdn.jsdelivr.net/npm/dplayer/dist/DPlayer.min.js

// @require https://cdn.jsdelivr.net/npm/hls.js/dist/hls.min.js

// @icon https://tv.cctv.com/favicon.ico

// @connect vdn.apps.cntv.cn

// @connect hls.cntv.myhwcdn.cn

// @connect newcntv.qcloudcdn.com

// @grant GM_xmlhttpRequest

// @grant GM_addStyle

// @grant unsafeWindow

// ==/UserScript==

(function() {

var util = (function () {

function util() {}

util.xhr = function (xhrData) {

return new Promise(function(resolve, reject) {

if (!xhrData.xhr) {

GM_xmlhttpRequest({

method: xhrData.method || "get",

url: xhrData.url,

data: xhrData.data,

headers: xhrData.headers || {},

responseType: xhrData.type || "",

timeout: 3e4,

onload: function onload(res) {

return resolve({ response: res, body: res.response });

},

onerror: reject,

ontimeout: reject

});

} else {

var xhr = new XMLHttpRequest();

xhr.open(xhrData.method || "get", xhrData.url, true);

if (xhrData.method === "post") {xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded; charset=utf-8");}

if (xhrData.cookie) {xhr.withCredentials = true;}

xhr.responseType = xhrData.responseType || "";

xhr.timeout = 3e4;

if (xhrData.headers) {for (var k in xhrData.headers) {xhr.setRequestHeader(k, xhrData.headers[k]);}}

xhr.onload = function(ev) {

var evt = ev.target;

resolve({ response: evt, body: evt.response });

};

xhr.onerror = reject;

xhr.ontimeout = reject;

xhr.send(xhrData.data);

}

});

};

util.createElement = function (data) {

var node;

if (data.node) {

node = document.createElement(data.node);

if (data.content) {this.setElement({node: node, content: data.content});}

if (data.html) {node.innerHTML = data.html;}

}

return node;

};

util.setElement = function (data) {

if (data.node) {

for (let name in data.content) {data.node.setAttribute(name, data.content[name]);}

if (data.html!=undefined) {data.node.innerHTML = data.html;}

}

};

return util;

})();

var h5onCCTV = (function () {

function h5onCCTV() {};

h5onCCTV.prototype.addPlayer = function (m3u8) {

var h5css = util.createElement({node: 'link', content: {rel: 'stylesheet', href: 'https://cdn.jsdelivr.net/npm/dplayer/dist/DPlayer.min.css'}});

document.head.appendChild(h5css);

var container = document.querySelector('.video_left');

GM_addStyle('.gwA151201_ind01, .retrieve, .buttonVal, #page_body > .column_wrapper, .video, .video .right_but, .cnt_share, [class^=jscroll] {z-index: auto !important;} .nav2 > div > div {z-index: 1 !important;}');

util.setElement({node: container, content: {style: 'height: 100%'}, html: '

var pip = document.pictureInPictureEnabled ? [{text: '画中画模式', click: function () {document.querySelector('.dplayer-video').requestPictureInPicture().catch(console.log);}}] : [];

var dp = new DPlayer({

container: container.children[0],

video: {

quality: m3u8,

defaultQuality: m3u8.length-1

},

preload: 'none',

contextmenu: pip

});

unsafeWindow.dp = dp;

var curTime = localStorage.getItem(unsafeWindow.guid);

if (curTime) {

dp.seek(curTime);

var showTime = '';

if (curTime > 3600) {showTime += ' '+parseInt(curTime/3600)+' 时'; curTime = curTime%3600;}

if (curTime > 60) {showTime += ' '+parseInt(curTime/60)+' 分'; curTime = curTime%60;}

showTime += ' '+parseInt(curTime)+' 秒';

dp.notice('已跳转到上次观看进度'+showTime, 2000);

}

dp.on('timeupdate', function () {

if ((dp.video.duration-dp.video.currentTime > 30) && dp.video.currentTime > 30) {

localStorage.setItem(unsafeWindow.guid, dp.video.currentTime);

}

else {

localStorage.removeItem(unsafeWindow.guid);

}

});

}

h5onCCTV.prototype.run = function () {

var _this = this;

util.xhr({

url: `https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid=${unsafeWindow.guid}`,

type: 'json'

}).then(function (res) {

var url = res.body.hls_url.replace('://', '/').split('/');

url = `${url[0]}://newcntv.qcloudcdn.com/${url.slice(2).join('/')}`;

util.xhr({

url: url

}).then(function (res) {

var vlist = res.body.split('\n');

var m3u8 = [];

vlist.forEach(function (v) {

if (v.indexOf('/200.m3u8')>-1) {m3u8.push({name: '流畅', url: 'https://newcntv.qcloudcdn.com'+v, type: 'hls'});}

else if (v.indexOf('/450.m3u8')>-1) {m3u8.push({name: '低清', url: 'https://newcntv.qcloudcdn.com'+v, type: 'hls'});}

else if (v.indexOf('/850.m3u8')>-1) {m3u8.push({name: '标清', url: 'https://newcntv.qcloudcdn.com'+v, type: 'hls'});}

else if (v.indexOf('/1200.m3u8')>-1) {m3u8.push({name: '高清', url: 'https://newcntv.qcloudcdn.com'+v, type: 'hls'});}

else if (v.indexOf('/2000.m3u8')>-1) {m3u8.push({name: '超清', url: 'https://newcntv.qcloudcdn.com'+v, type: 'hls'});}

});

_this.addPlayer(m3u8);

});

});

};

return h5onCCTV;

})();

var program = new h5onCCTV();

program.run();

})();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
HTML5作品说明 一、主题内容 随着信息技术的发展,计算机已被广泛的应用于社会的各个领域,成为推动社会发展的技术动力。根据老师课堂所讲内容,我做了一个动漫网页,作为作业内容。 我做的网页的主题是关于一部动漫的,名字叫做《名侦探柯南》,讲的是在一个被黑社会暗算身体变小的少年,侦破一个个奇珍议案的故事。整个网页包括柯南首页、视频欣赏、任务介绍、柯南的道具、站长信息、留言板六部分。其中最为丰富的主页又包括柯南的介绍、动漫作者两个大模块。而其余部分则是各有特点,精彩纷呈。 二、制作过程 下面介绍主要页面制作过程。 首先每个网页有相同的导航栏,设置了背景图片与各个功能的超链接。网页基本分为三大模块,利用html5标签+css修饰。留言板部分使用标签创建html表单。点击链接跳转相应网页。 精彩视频是从网上下载的mp4格式,将之放入文件夹map4下,使用标签定义媒介资源,并且点开页面自动加载运行。站长简介和注册使用了表单。文章分布、趣味游戏使用进行表单验证和动态内容修改。整个网页均使用了css,来完成本网页页面效果。 三、作业总结 此次的网页制作是对我们学习内容的一次检验。我对开发环境并不是很熟悉,在以前的学习中也只是涉及到简单的程序设计,一开始做的还是有点力不从心,但通过老师同学们的帮助和自己的学习,我已经使自己可以简单使用应用程序。通过制作这个网页,我掌握了制作的基本过程,了解了基本知识,而在这次设计的最大收获并不是掌握这门的应用,而是学会了设计网页的思维方法,以及与同学间相互帮助精神。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值