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

网站建设的经费预算报告wordpress注册中文

网站建设的经费预算报告,wordpress注册中文,网站镜像代理怎么做,seo 专业为网站建设文章目录 前言需求分析实施观察页面起始渲染编码效果展示 总结 前言 新手上路,欢迎指导 需求分析 想要一个简约干净的界面,需要去除推荐栏和广告部分. 想要自由调节视频播放速率,需要在视频控制栏加一个输入框控制视频倍速 实施 观察页面起始渲染 因为要使用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/591679.html

相关文章:

  • 分享型网站成品软件源码网站大全
  • 定制网站制作公司有哪些3d装修设计软件
  • 青岛建网站的公司有哪些杭州模板网站建设
  • 江苏网站建设基本流程refile自己做的网站
  • 苏州工业园区建设局网站静安网站建设哪里有
  • 做淘宝客要自己的网站做复印机的模板网站
  • 网站开发产生的材料3d网站建设
  • 优化网站的目的股份有限公司
  • 天堂网长尾关键词挖掘网站文山网站建设联系电话
  • 南宁网站制作价格wordpress 查询数据
  • 百度网站权重排名做ui要上那些网站
  • 广告制作公司网站建设模板国内做卷学习网站
  • 网站开发知识产权套网站模板软件
  • 失物招领网站开发项目需求分析nas上建设网站
  • 成都最新规划官方消息站内seo是什么意思
  • 购物网站建设方案书重庆南坪网站建设
  • 做网站网站名字自己设置吗中国网站建设集团
  • 在国外服务器上做网站项目如何赚钱wordpress notes
  • 网站构建免费wordpress 页面栏目
  • 重庆做网站好的公司免费开源企业网站程序
  • 互联网金融p2p网站建设福田网站建设哪家好
  • 河北搜恒不给做网站广州有什么好玩的东西
  • 网站分为几种页面设计总结
  • php做网站视频wordpress怎么建商场
  • 网站怎么推广效果好一点呢软件开发工程师介绍
  • 北京专业网站优化各大门户网站有哪些
  • 中小型网站建设资讯wordpress 制作支付页
  • 淘客网站怎么建设西安最好的室内设计公司
  • 网站开发的公司个人做网站有什么用
  • 公众号文案里怎么做网站链接学校网站建设说明材料