天道酬勤,厚德载物,自强不息,求真务实,动脑动手,孜孜以求

StudyDo

天道酬勤,厚德载物,自强不息,求真务实,动脑动手,孜孜以求

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

初始化脚本

// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://core.teacher.vocational.smartedu.cn/p/course/vocational/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=smartedu.cn
// @grant        none

命名进行修改

// @name         寒假课程视频点击
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://core.teacher.vocational.smartedu.cn/p/course/vocational/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=smartedu.cn
// @grant        none

屏蔽广告的方法

  • 获取标签
  • 删除元素,this.remove(), this.parentElement.remove();, this.parentNode.remove();
  • 隐藏元素,this.parentElement.style.display = 'none'; this.parentElement.setAttribute('style','display:none');

获取元素,常用方法

document.getElementsByClassName() 返回文档中所有指定类名的元素集合,作为 NodeList 对象。
document.getElementById() 返回对拥有指定 id 的第一个对象的引用。
document.getElementsByName() 返回带有指定名称的对象集合。
document.getElementsByTagName() 返回带有指定标签名的对象集合。

操作元素

点击click,删除remove,隐藏hide,根据情况使用。

操作试用

在网页开发界面进行测试
看是否可行。如果可行,就往下继续

设置定时器

    setInterval(() => {
        方法
    }, 毫秒数);

设置定时器变量

    let tips=setInterval(() => {
        $(()=>{
            console.log("启动完成");
            if ($('.layui-layer').length){
                console.log($('.layui-layer').length)  
                var btn=document.getElementsByClassName('layui-layer-btn0')[0];
                if (btn){
                    btn.click();
                    clearInterval(tips);
                    console.log("关闭提示");  
                }                
            }
        });  
    }, 3000);

设置定时器取消的设定

clearInterval(tips);
posted on 2023-02-03 15:24  三木人  阅读(1228)  评论(0编辑  收藏  举报