- UID
- 7138
- 精华
- 积分
- 713
- 威望
- 点
- 宅币
- 个
- 贡献
- 次
- 宅之契约
- 份
- 最后登录
- 1970-1-1
- 在线时间
- 小时
|
如题,直播页面元素太多,影响观看体验,直接精简到只剩播放器,也没有弹幕和公屏
- (function() {
- 'use strict';
-
- if (location.pathname.includes("channel")) {
- // 动态加载依赖
- [ 'https://cdnjs.cloudflare.com/ajax/libs/dplayer/1.27.1/DPlayer.min.js',
- 'https://cdnjs.cloudflare.com/ajax/libs/hls.js/1.5.18/hls.min.js'
- ].forEach(src => {
- const script = document.createElement('script');
- script.src = src;
- document.body.appendChild(script);
- });
- // 获取直播数据并初始化播放器
- fetch(location.href)
- .then(r => r.json())
- .then(data => data?.data[0])
- .then(data => {
- if (data?.is_audiolive === 1) {
- document.body.innerHTML = "<h1>音频直播,暂不支持</h1>";
- return;
- }
-
- setTimeout(() => initPlayer(data), 500);
- });
- function initPlayer(data) {
- document.body.innerHTML = '';
- document.title = data.nickname;
-
- const playerContainer = document.createElement('div');
- playerContainer.id = 'dplayer';
- playerContainer.style.cssText = 'width:64%; height:auto; margin:0 auto';
-
- const link = document.createElement('a');
- link.href = `https://cc.163.com/${data.ccid}`;
- link.textContent = `直播间${data.ccid}于${data.startat}开播`;
-
- document.body.append(playerContainer, link);
-
- new DPlayer({
- container: playerContainer,
- live: true,
- volume: 1.0,
- video: {
- url: data.sharefile,
- type: 'hls',
- pic: data.cover
- }
- }).fullScreen.request('web').play();
- }
- } else {
- // 非channel页面处理
- const roomData = __NEXT_DATA__?.props?.pageProps?.roomInfoInitData?.live;
- if (!roomData) return;
-
- if (roomData.gametype === 95599) {
- alert("聊天室不支持弹出播放器播放");
- } else if (roomData.status > 0) {
- const cid = roomData.cid || roomData.channel_id;
- cid > 0 && (location.href = `//cc.163.com/live/channel/?channelids=${cid}`);
- } else {
- alert("未直播");
- }
- }
- })();
复制代码 |
|