移动端网页CSDN去除弹框

问题

移动端浏览器打开CSDN网站,

  • 经常会弹出在浏览器里还是APP中打开弹框。
  • 经常会自动跳转到CSDN APP。
  • 未登录弹框
  • 查看全文弹框

解决方法

主要功能:

  • 弹框屏蔽
  • 展开全文
  • 展开代码片段
  • 跳转 APP 屏蔽

部分手机浏览器支持自定义 JavaScript 扩展,下面以Alook 浏览器为例。在Alook浏览器中,

  • 设置→自定义设置→JavaScript扩展
  • 点击加号新建一个“被动扩展”,名称任意
  • 匹配类型选择域名
  • 匹配值为: blog.csdn.net
  • 运行时间 DOMContentLoaded
  • 粘贴JavaScript代码并存储:

let timer = setInterval(() => {
    if (document.querySelector('.weixin-shadowbox')) {
        document.querySelector('.weixin-shadowbox')?.remove();
        document.querySelector('.btn_open_app_prompt_div')?.remove();
        document.querySelector("#btn_open_app_prompt_item")?.remove();
        document.querySelectorAll('.open_app_channelCode').forEach(el=>el?.remove())


        document.querySelector(".feed-Sign-span.feed-Sign-style-new.open_app_channelCode")?.remove()
        
    
        document.querySelector(".article_content").style.height="fit-content"
        document.querySelector('.app-shadowbox')?.remove();
        document.querySelector('.btn_mod')?.remove();
        document.querySelector('.readall_box')?.remove();
        document.querySelector('.btn_open_app_prompt_box.detail-open-removed')?.remove();
        document.querySelector("#btn_open_app_prompt_item")?.remove();
    
        document.body.animate({ scrollTop: 0 }, 0);
        document.querySelectorAll('.hide-preCode-bt').forEach(el=>el?.click())
        document.querySelectorAll('.open_app_channelCode').forEach(el=>el?.click())
        clearInterval(timer);
    }
}, 200);

let loginTimer = setInterval(()=>{
    if(document.querySelector(".passport-login-container")){
        document.querySelector(".passport-login-container").remove()
        clearInterval(loginTimer)
    }
},300)

可改进点

  • 当前代码为避免跳转APP,将所有点击会跳转APP的部分移除,故会移除推荐文章的部分内容。
  • 部分网页产看可能会出现弹框闪一下的情况,并不影响内容查看
  • 代码复制功能,没有完善,可以添加相关代码实现
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值