Skip to content

Commit

Permalink
中央台换台优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Eanya-Tonic committed Sep 21, 2024
1 parent 6bf1662 commit b9fb944
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions app/src/main/java/com/eanyatonic/cctvViewer/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,50 @@ public void onReceivedSslError(com.tencent.smtt.sdk.WebView webView, com.tencent

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// 页面加载时执行 JavaScript 脚本
view.evaluateJavascript(
"""
function FastLoading() {
const fullscreenBtn = document.querySelector('#player_pagefullscreen_yes_player') || document.querySelector('.videoFull');
if (fullscreenBtn) return;
// 清空所有图片的 src 属性,阻止图片加载
Array.from(document.getElementsByTagName('img')).forEach(img => {
img.src = '';
});
// 清空特定的脚本 src 属性
const scriptKeywords = ['login', 'index', 'daohang', 'grey', 'jquery'];
Array.from(document.getElementsByTagName('script')).forEach(script => {
if (scriptKeywords.some(keyword => script.src.includes(keyword))) {
script.src = '';
}
});
// 清空具有特定 class 的 div 内容
const classNames = ['newmap', 'newtopbz', 'newtopbzTV', 'column_wrapper'];
classNames.forEach(className => {
Array.from(document.getElementsByClassName(className)).forEach(div => {
div.innerHTML = '';
});
});
// 递归调用 FastLoading,每 4ms 触发一次
setTimeout(FastLoading, 4);
}
FastLoading();
"""
,
value -> {
});
super.onPageStarted(view, url, favicon);
}

// 设置 WebViewClient,监听页面加载完成事件
@Override
public void onPageFinished(WebView view, String url) {
// 页面加载完成后执行 JavaScript 脚本

// 清空info
info = "";

Expand Down Expand Up @@ -291,19 +327,19 @@ public void onPageFinished(WebView view, String url) {
view.evaluateJavascript(
"""
function af(){
function AutoFullscreen(){
var fullscreenBtn = document.querySelector('#player_pagefullscreen_yes_player')||document.querySelector('.videoFull');
if(fullscreenBtn!=null){
//alert(fullscreenBtn)
fullscreenBtn.click();
document.querySelector('video').volume=1;
}else{
setTimeout(
()=>{ af();}
()=>{ AutoFullscreen();}
,16);
}
}
af()
AutoFullscreen()
"""
,
value -> {
Expand All @@ -318,7 +354,7 @@ function af(){

// 显示覆盖层,传入当前频道信息
showOverlay(channelNames[currentLiveIndex] + "\n" + info);
}, 1000);
}, 500);
}
});

Expand All @@ -332,7 +368,7 @@ function af(){
webView.setFocusable(false);

// 开启无图(X5内核)
if(canLoadX5) {
if (canLoadX5) {
webView.getSettingsExtension().setPicModel(IX5WebSettingsExtension.PicModel_NoPic);
}
// 设置 WebView 客户端
Expand Down

0 comments on commit b9fb944

Please sign in to comment.