当前位置: 首页 > wzjs >正文

mvc网站开发 案例视频参考消息今天新闻

mvc网站开发 案例视频,参考消息今天新闻,深圳建设银行分行网站,江西省住房和城乡建设厅的网站文章目录 前言需求分析实施观察页面起始渲染编码效果展示 总结 前言 新手上路,欢迎指导 需求分析 想要一个简约干净的界面,需要去除推荐栏和广告部分. 想要自由调节视频播放速率,需要在视频控制栏加一个输入框控制视频倍速 实施 观察页面起始渲染 因为要使用MutationObse…

文章目录

  • 前言
  • 需求分析
  • 实施
    • 观察页面起始渲染
    • 编码
    • 效果展示
  • 总结


前言

新手上路,欢迎指导

需求分析

想要一个简约干净的界面,需要去除推荐栏和广告部分.
想要自由调节视频播放速率,需要在视频控制栏加一个输入框控制视频倍速

实施

观察页面起始渲染

因为要使用MutationObserver监控元素,所以需要确认页面开始渲染了哪些东西

  • 打个断点:
    在这里插入图片描述
  • 刷新:

在这里插入图片描述

经观察(需要动手看结果)发现,页面基本框架已经渲染完成了,侧边的推荐和广告,顶部左侧的导航栏都有了.
缺少中间的搜索框,视频控件,底部评论

这里怎么清理全靠喜好:
左上导航栏不喜欢,留一个首页,
右侧广告和推荐都不喜欢,去除不要

编码

清理的基本思路就是找到不要的元素的类名或id,创建个样式直接display: none !important,有要保留的就父元素display: none再把个别要保留的部分换回原来的显示属性,不行就不要的一一display: none !important
插入搜索框拿到值改下video的playbackRate即可

  1. 准备一个插入css的函数.
function addNewStyle(newStyle) {let styleElement = document.getElementById('mystyles');if (!styleElement) {styleElement = document.createElement('style');styleElement.type = 'text/css';styleElement.id = 'mystyles';document.getElementsByTagName('head')[0].appendChild(styleElement);}styleElement.appendChild(document.createTextNode(newStyle));
}
  1. 预定义全局样式
const cssVars = {hide_force: 'display: none !important',hide: 'display: none',show_as_item: 'display: list-item'
};
  1. 在window加载时加入逻辑监听body插入元素时去掉左上导航除图标首页以外的部分,就完成了.
    不太放心又加了个定时器来去除之前遇到的其他广告.
    评论区是一个单独的组件,封装在shadow DOM里,所以直接用定时器解决了.
//二次初始化页面
const observerInto = new MutationObserver(function () {const cssConfig = {hiddenList: {selectors: ['.ad-report', '.recommend-list-v1', '.slide-ad-exp'],props: cssVars.hide_force},headerCleanup: {selectors: ['#biliMainHeader .left-entry li'],props: cssVars.hide},headerRetain: {selectors: ['#biliMainHeader .left-entry li:first-child'],props: cssVars.show_as_item,}};addNewStyle(compileCSS(cssConfig))observerInto.disconnect()
})
observerInto.observe(document.body, {childList: true, subtree: true})
//去除其他广告
setTimeout(function () {const cssConfig = {hiddenAds: {selectors: ['.vcd', '.video-card-ad-small', '.activity-m-v1', '.act-end'],props: cssVars.hide_force}};addNewStyle(compileCSS(cssConfig));}, 2000);
//去除评论区notice公告
setTimeout(function () {const shadowHost = document.querySelector('bili-comments').shadowRoot.querySelector('bili-comments-header-renderer');// 获取 Shadow Rootconst shadowRoot = shadowHost.shadowRoot;// 如果 Shadow DOM 是开放的(open),可以直接访问if (shadowRoot) {// 在 Shadow DOM 中查找元素const noticeElement = shadowRoot.querySelector('#notice');console.log(noticeElement)if (noticeElement) {noticeElement.setAttribute('style', 'display: none !important');}} else {console.log('Shadow DOM 是封闭的(closed),无法访问');}
}, 6000);
  1. 监听搜索框值的变化,改成喜欢的值(需要注意,点击搜索还是搜索原来的内容)
const observerSearchBar = new MutationObserver(function () {const input = document.querySelector('#nav-searchform input')if (input && input.placeholder && input.placeholder !== '好好学习,天天向上') {input.placeholder = '好好学习,天天向上'input.title = '好好学习,天天向上'}
})
const centerSearchContainer = document.querySelector('#biliMainHeader');
observerSearchBar.observe(centerSearchContainer, {subtree: true,attributes: true,attributeFilter: ['placeholder']
})
  1. 监听视频控件渲染,插入自定义输入框
const playerContralBottom = document.querySelector(".bpx-player-control-bottom-right");
const observerContralBottom = new MutationObserver(function () {if (playerContralBottom.children.length >= 2) {const input = document.createElement('input');Object.assign(input, {type: 'text',maxLength: 4,placeholder: '✍️ 播放倍率',style: `
width: 72px;
height: 24px;
padding: 2px 0 2px 4px;
font-size: 12px;
font-weight: bold;
background: linear-gradient(45deg, #f3ec78, #af4261);
border: 1px solid #fff;
border-radius: 15px;
box-shadow: 0 4px 15px rgba(175,66,97,0.3);
color: #fff;
text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
`});input.addEventListener('focus', () => {input.style.transform = 'scale(1.05)';input.style.boxShadow = '0 8px 25px rgba(175,66,97,0.4)';input.style.borderColor = '#ffd700';});input.addEventListener('blur', () => {input.style.transform = 'scale(1)';input.style.boxShadow = '0 4px 15px rgba(175,66,97,0.3)';input.style.borderColor = '#fff';});
//终止监听,避免插入监听死循环observerContralBottom.disconnect()playerContralBottom.insertBefore(input, playerContralBottom.children[1]);input.addEventListener('input', function () {// 输入警告效果if (this.value.length === 4) {this.style.background = 'linear-gradient(45deg, #af4261, #f3ec78)';setTimeout(() => {this.style.transform = 'translateX(5px)';setTimeout(() => {this.style.transform = 'translateX(-5px)'}, 50);}, 0);} else {this.style.transform = 'scale(1.05)';this.style.background = 'linear-gradient(45deg, #f3ec78, #af4261)';}});//核心逻辑在这里input.addEventListener('keydown', function (event) {if (event.key === 'Enter') {//console.log('你按下了回车键,当前输入的值是:', this.value);const regex = /\d+(\.\d+)?/if (!regex.test(this.value)) {alert("输入值非法");this.value = ''return;}const video = document.querySelector("video");let rate = parseFloat(this.value).toFixed(2);rate = rate < 0.1 ? (() => {alert("不能低于0.1倍速!已调整为0.1")return 0.1})() : rate > 16 ? (() => {alert("不能高于16倍速!已调整为16")return 16})() : ratevideo.playbackRate = ratethis.value = ''}});}
})
observerContralBottom.observe(playerContralBottom, {childList: true, subtree: true})

效果展示

在这里插入图片描述

总结

主要就用到MutationObserver和定时器,以及video.playbackRate

输入框那一大段基本是deepseek生成的,加了些样式和动画.

{childList: true, subtree: true,attributes: true, attributeFilter: ['placeholder']}
用到了四个选项

  • 监听自身或子节点插入
  • 监听整个子树
  • 监听属性变化
  • 要监听的属性值(默认不加全监听)
http://www.dtcms.com/wzjs/315833.html

相关文章:

  • 建站新体验做网络推广为什么会被抓
  • 设计做网站免费搭建网站的软件
  • 常州做网站哪家便宜北京网站优化价格
  • 随州网站建设价格网站优化怎么操作
  • 手机做网站视频微信软文广告经典案例
  • 大连做网站仟亿科技新型实体企业100强
  • 页网站设计上海搜索引擎推广公司
  • 做门户网站的意义在哪网络营销业务流程
  • 设计的商城网站建设seo搜索引擎优化工程师招聘
  • 阿里云 全国网站建设优化设计电子版在哪找
  • 浙江省建设信息港网站搜索引擎seo关键词优化效果
  • 郑州一凡网站建设做网站用什么软件
  • 在自己的网站做外链北京seo优化多少钱
  • 免费企业黄页网站网址超级优化
  • 携程网站建设的基本特点百度推广没有一点效果
  • 自己做优惠劵网站杭州互联网公司排名榜
  • 南京计算机培训机构哪个最好长沙seo管理
  • 优惠券的网站制作seo工资服务
  • 石家庄医院网站建设北京seo收费
  • 电商网站如何提高转化率微信小程序开发文档
  • 汕头站扩建进展宣传推广方案范文
  • 天津网站建设推广个人网页模板
  • 做兼职什么网站靠谱小广告清理
  • 怎么做室内设计公司网站佛山市seo推广联系方式
  • 龙岩网站建设亿网行百度之家
  • 济南优化网站厂家友情链接检测
  • 徐州市网站互联网项目推广平台有哪些
  • 网站收藏以后怎样做桌面快捷键关键词优化公司靠谱推荐
  • 郑州网站优化公司排名苏州seo网站管理
  • 在线上传图片生成链接seo的主要工作是什么