pojin (ID: 1)
头衔:论坛坛主
等级:究级天王[荣誉]
积分:2826
发帖:230 篇
来自:保密
注册:2023-12-09 09:36:49
造访:2026-05-05 13:56:22
发帖:230 篇
来自:保密
注册:2023-12-09 09:36:49
造访:2026-05-05 13:56:22
[ 第 1 楼 ]
104
回复
安装 Node.js:
winget install openjs.nodejs安装 electron 模块:npm i electron --registry=https://registry.npmmirror.com放入 index.js,并运行命令:npx electron .index.js 内容如下: var { app, BrowserWindow, Menu } = require('electron');
// 频道列表
var progs = [
"https://tv.cctv.com/live/cctv1/",
"https://tv.cctv.com/live/cctv2/",
"https://tv.cctv.com/live/cctv3/",
"https://tv.cctv.com/live/cctv4/",
"https://tv.cctv.com/live/cctv5/",
"https://tv.cctv.com/live/cctv6/",
"https://tv.cctv.com/live/cctv7/",
"https://tv.cctv.com/live/cctv8/",
"https://tv.cctv.com/live/cctvjilu/",
"https://tv.cctv.com/live/cctv10/",
"https://tv.cctv.com/live/cctv11/",
"https://tv.cctv.com/live/cctv12/",
"https://tv.cctv.com/live/cctv13/",
"https://tv.cctv.com/live/cctvchild/",
"https://tv.cctv.com/live/cctv15/",
"https://tv.cctv.com/live/cctv16/",
"https://tv.cctv.com/live/cctv17/"
];
// 播放指定频道
function play(ch) {
// “00”指令为退出观看
if(ch == "00") return app.quit();
var url = progs[ch - 1];
if(!url) return;
ctrl.chanel = ch;
ctrl.win.loadURL(url);
// 如果存在 video 标签,则请求全屏
ctrl.win.webContents.on('did-finish-load', () => {
ctrl.win.webContents.removeAllListeners('before-input-event');
ctrl.win.webContents.on("before-input-event", (e, input) => {
if (input.type == "keyUp") ctrl.onkey(input.key);
});
setTimeout(() => {
// 模拟触发一次按键
ctrl.win.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'ArrowLeft' });
ctrl.win.webContents.sendInputEvent({ type: 'keyUp', keyCode: 'ArrowLeft' });
ctrl.win.webContents.executeJavaScript(`self.tvCtrl = new ${tvFunc}(${ch});`);
}, 100);
});
}
// 电视注入函数【显示频道】
function tvFunc(curCH) {
this.showCH = function(ch) { b.style.display = "block"; b.innerHTML = ch; };
var tv = document.querySelector("video").parentNode;
var b = document.createElement("b");
b.style.cssText = "position: fixed; color: #0f0; font: bold 10vh/15vh arial; top: 5vh; right: 5vw; z-index: 9";
tv.appendChild(b).innerHTML = curCH;
setTimeout(() => { b.style.display = "none"; }, 3210);
// 请求全屏播放
tv.requestFullscreen();
}