首页 > 其他分享 >油猴脚本(一)学习通讨论点赞 v1.0

油猴脚本(一)学习通讨论点赞 v1.0

时间:2024-11-24 18:34:50浏览次数:12  
标签:unlikeButton style likeButton pauseButton v1.0 let 点赞 menuDOM 油猴

注释很详细,直接上代码

// ==UserScript==
// @name         桑桑脚本一号
// @namespace    http://tampermonkey.net/
// @version      2024-11-21
// @description  学习通讨论点赞 v1.0
// @author       眨眼睛&&洛洛
// @match        https://groupweb.chaoxing.com/course/topic/topicList*
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAY1BMVEUqpQsqpRUqpRUqpRUppBUqpBUqpRQqpRQqpRUqpRUqpRYqpRUnpBsqpRUqpRUqpBYppBUpphYqpRUqpRQqpRUqpRUqpRUqpRUpphUrpRUqpRUqpRQqpRUqpRQppRUqpRUqpRXRpjWOAAAAIHRSTlMAc+PDoII0G/OWU7QJYcYiQxTUZenf99C/XzCufU3wkc0k4ycAAAt0SURBVHja7V1pe7I6EBVkkUVBUfGtovz/X3nRtkpmy8QF7X043yohyUlmzkxCoJPJiBEjRowYMWLEiBEjRowYMWLEiP8pPN+fBmH07m48iDictd9I/jKVKGh7CN/dnXuRZq2JIH93l+7BfNoiLIp398oZ6aKlELy7X44os5ZB+u6uuaAIWhaLeOjeLMN2lSXhHe1Wa55HmwxM4zqo69DRP2NhOtrNwApsmPjWqfG0FnjUw3oIkn8HcwhbGcFw+kvJv1Y0o11rw2wg42LkX9e66OVXVAPQiFhHLRV3JxoaHf69mkYsGPjULsOBkkfbfr2WR+ULbdv9fa/moTPUKrlPF6Ro3Nb2phdqGl1sstaWH3zV6DlOh2+/X3TzKgS1W/w9/i3vnGLGFrvIbBVINwfLroDnYFu9QXWck1KKxhqrlqwyJdqQ+tcYsWjuwsNr7RCNgZvH83Rc1a4vibzJFEDDNw5Jq0r+fUFCmFu8boAOt1JxnyI7pshV1YlAzi6BTPCDSMtEHU0i38gRexd3dE1fhKsqhOaCpVo2OW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qta5H4a8ScAq8WMinhsPsNpTbsR9HsyDvNvBz+8+DcYp8bp8d3fuR29Lp/b+nIP38Dsjs331J//X6w3nBNE//T21xUj//L91HjFixIgRI0aMGDFixIgRI0aMeDb+A8GbtsQaz3w6AAAAAElFTkSuQmCC
// @grant        unsafeWindow
// ==/UserScript==

(function () {
    'use strict';

    //脚本是否正在运行
    let isRunning = false;

    //点赞or清除点赞
    let likeOrClear = true;

    //菜单DOM
    let menuDOM = void (0);

    //全部点赞按钮DOM
    let likeButton = void (0);

    //全部取消点赞按钮DOM
    let unlikeButton = void (0);

    //暂停按钮DOM
    let pauseButton = void (0);

    //总操作数量
    let totalCount = 0;

    //延时计数器
    let delayCount = 0;

    //获取iframe框架内容
    let getIframeContent = (iframeDOM) => {
        return iframeDOM.contentWindow.document;
    }

    //判断所有节点是否全部符合要求
    let isAllNodesFited = () => {
        let liDOMList = document.querySelectorAll("li.dataBody_td.dataBody_topic");

        if (likeOrClear) {
            return Array.from(liDOMList).every((liDOM) => {
                let likeDOM = liDOM.querySelector(".like");
                return likeDOM.classList.contains("active")
            })
        } else {
            return Array.from(liDOMList).every((liDOM) => {
                let likeDOM = liDOM.querySelector(".like");
                return !likeDOM.classList.contains("active")
            })
        }
    }


    //在课程讨论界面遍历未分类的讨论
    let traverseUnclassifiedDiscussion = () => {
        // let iframeDOM = document.querySelector("#frame_content-tl");
        // let iframeDOM_src = iframeDOM.src;
        // window.open(iframeDOM_src);

        //获取li且类名有dataBody_td和dataBody_topic的节点集合
        let liDOMList = document.querySelectorAll("li.dataBody_td.dataBody_topic");

        //获取长度
        let liDOMListLength = liDOMList.length;

        let delayCountChange = () => {
            delayCount++;

            // if (delayCount / 5 == 0) {
            //     console.log(delayCount);
            //     delayCount += 10;
            // }
        }
        delayCount = 0;
        //遍历获取其中类名为like的节点
        liDOMList.forEach((liDOM) => {
            let likeDOM = liDOM.querySelector(".like");

            setTimeout(() => {
                //获取like节点
                let likeDOM = liDOM.querySelector(".like");
                if (isRunning) {
                    if (likeOrClear) {
                        //如果节点类名不存在active则点击
                        if (!likeDOM.classList.contains("active")) {
                            likeDOM.click();
                            totalCount++;

                        }
                    } else {
                        if (likeDOM.classList.contains("active")) {
                            likeDOM.click();
                            totalCount++;

                        }
                    }
                    liDOMListLength--;

                    if (liDOMListLength == 0 && (!isAllNodesFited())) {
                        traverseUnclassifiedDiscussion()
                    }
                }
            }, 200 * Math.floor(delayCount))//防风控
            if (!likeDOM.classList.contains("active") && (likeOrClear)) {
                delayCountChange()
            } else if (likeDOM.classList.contains("active") && (!likeOrClear)) {
                delayCountChange()
            }
        })
    }

    //循环点击加载更多
    let clickLoadMore = () => {
        let loadMoreDOM = document.querySelector(".loadText");

        //如果diplay属性不为none则点击
        if (loadMoreDOM.style.display !== "none") {
            loadMoreDOM.click();
        }
    }

    //获取样式表中的指定元素
    let getComputedStyleItem = (cssDeclaration, value) => {
        const itemCssValue = String(cssDeclaration.getPropertyValue(value)).trim()

        return itemCssValue
    }

    // 获取当前加载更多的状态
    let getLoadMoreStatus = () => {
        let loadMoreDOM = document.querySelector(".loadText");
        const loadMoreCss = getComputedStyle(loadMoreDOM);
        if (getComputedStyleItem(loadMoreCss, 'display') == "inline-block") {
            return 'loadText';
        }

        loadMoreDOM = document.querySelector(".loadingText");
        const loadingCss = getComputedStyle(loadMoreDOM);
        if (getComputedStyleItem(loadingCss, 'display') == "inline-block") {
            return 'loadingText';
        }

        loadMoreDOM = document.querySelector(".loadEndText");
        const loadEndCss = getComputedStyle(loadMoreDOM);
        if (getComputedStyleItem(loadEndCss, 'display') == "inline-block") {
            return 'loadEndText';
        }


        return 'unknown';
    }



    //创建UI
    let createUI = () => {
        // 创建菜单容器
        menuDOM = document.createElement("div");
        menuDOM.style.position = "fixed";
        menuDOM.style.right = "20px";  // 菜单容器的横向位置
        menuDOM.style.top = "50%";   // 菜单容器的纵向位置
        menuDOM.style.width = "200px"; // 菜单宽度
        menuDOM.style.padding = "10px"; // 内边距
        menuDOM.style.backgroundColor = "#333"; // 背景颜色
        menuDOM.style.borderRadius = "8px"; // 圆角
        menuDOM.style.color = "#fff"; // 字体颜色
        menuDOM.style.textAlign = "center"; // 字体居中
        menuDOM.style.zIndex = "9999"; // 确保菜单在最上层

        // 创建“全部点赞”按钮
        likeButton = document.createElement("div");
        likeButton.innerHTML = "全部点赞";
        likeButton.style.width = "100%";
        likeButton.style.height = "40px";
        likeButton.style.marginBottom = "10px";
        likeButton.style.backgroundColor = "#4CAF50"; // 绿色
        likeButton.style.color = "#fff";
        likeButton.style.textAlign = "center";
        likeButton.style.lineHeight = "40px";
        likeButton.style.cursor = "pointer";
        likeButton.style.borderRadius = "4px";
        likeButton.onclick = () => {

            likeOrClear = true;
            run();
        };

        // 创建“全部取消”按钮
        unlikeButton = document.createElement("div");
        unlikeButton.innerHTML = "全部取消";
        unlikeButton.style.width = "100%";
        unlikeButton.style.height = "40px";
        unlikeButton.style.marginBottom = "10px";
        unlikeButton.style.backgroundColor = "#f44336"; // 红色
        unlikeButton.style.color = "#fff";
        unlikeButton.style.textAlign = "center";
        unlikeButton.style.lineHeight = "40px";
        unlikeButton.style.cursor = "pointer";
        unlikeButton.style.borderRadius = "4px";
        unlikeButton.onclick = () => {

            likeOrClear = false;
            run();
        };

        // 创建“暂停”按钮
        pauseButton = document.createElement("div");
        pauseButton.innerHTML = "暂停";
        pauseButton.style.width = "100%";
        pauseButton.style.height = "40px";
        pauseButton.style.marginBottom = "10px";
        pauseButton.style.backgroundColor = "#ff9800"; // 橙色
        pauseButton.style.color = "#fff";
        pauseButton.style.textAlign = "center";
        pauseButton.style.lineHeight = "40px";
        pauseButton.style.cursor = "pointer";
        pauseButton.style.borderRadius = "4px";
        pauseButton.onclick = () => {

            // 这里执行暂停操作的代码
            pause();
        };

        // 将按钮添加到菜单容器中
        menuDOM.appendChild(likeButton);
        menuDOM.appendChild(unlikeButton);
        menuDOM.appendChild(pauseButton);

        // 将菜单容器添加到页面
        document.body.appendChild(menuDOM);
    };

    //运行
    let run = async () => {
        isRunning = true;
        totalCount = 0;

        let promise = new Promise((resolve, reject) => {
            let timer = void (0);

            //定时器处理函数
            let timerSlove = () => {
                if (getLoadMoreStatus() == 'loadText') {

                    clickLoadMore()
                    clearTimerAndSlove()
                } else if (getLoadMoreStatus() == 'loadingText') {

                    clearTimerAndSlove()
                } else if (getLoadMoreStatus() == 'loadEndText') {

                    resolve();
                } else {
                    reject();

                }
            }

            //清理定时器并重新延时
            let clearTimerAndSlove = () => {
                clearInterval(timer);
                timer = setTimeout(timerSlove, 500);
            }

            clickLoadMore()

            //延时器
            timer = setInterval(timerSlove, 500);

        }).then(() => {
            traverseUnclassifiedDiscussion();
        })


    }

    //暂停
    let pause = () => {
        isRunning = false;
    }

    createUI();
})();

本脚本运行页面

请添加图片描述

由于学习通风控,眨眼睛做了判断处理,只要有节点未满足要求则会继续进行点赞,直到满足要求,可以忽略警告

标签:unlikeButton,style,likeButton,pauseButton,v1.0,let,点赞,menuDOM,油猴
From: https://blog.csdn.net/m0_73756108/article/details/144000740

相关文章

  • 希冀 操作系统 实验lab1 内核、Boot和printf(保姆级教程 建议点赞收藏 )
    这次我把所有代码都写出来方便大家复制(可以直接复制我的代码粘贴到终端执行)开始之前首先先拉取lab1的内容(一定先干这个,不然做不了实验!!!!!!!!!!!!!!!!)先切换到这个目录下cd20221105894-lab变为:输入gitpullgitcheckoutlab1 之后刷新一下你的学号-lab文件夹,如果改变了就好了,如果......
  • 网络管理 主机资源监控系统项目搭建 (保姆级教程 建议点赞 收藏)
    目录教大家实现图里面的2个仪表盘其他自行根据2个仪表盘的模式进行补充 一.首先准备实验环境需要环境python3.8.8下载完成之后开始配置虚拟环境二.开始编写代码先新建前提文件好了前提工作好了接下来就是写代码了  先写python代码 然后是main.html的代码......
  • vue入门案例-基本使用----非常适合初学者。言简意赅,没有废话。附带springboot+vue前后
    Listitemvue1.vue介绍渐进式JavaScript框架,易学易用,性能出色,适用场景丰富的Web前端框架地址:https://cn.vuejs.org/什么是vue?Vue(发音为/vjuː/,类似view)是一款用于构建用户界面的JavaScript框架。它基于标准HTML、CSS和JavaScript构建,并提供了一套声明......
  • 自制免费小说推文辅助工具:免费的文本转语音软件(v1.0),如果没有免费的软件那就自己做一个
    近在研究Pyqt的使用,于是准备做一些小工具练手。本文为自研免费推文助手软件系列第1篇文章,后面会持续更新。一、目标功能1、文本转语音:生成音频文件(.mp3);(v1.0)2、文本转语音:生成字幕文件(.srt);(v2.0)3、文本处理:去除无效行(空行、纯数字行)、去除特殊字符串;(v2.0)4、API服务:......
  • Jeff Dean点赞谷歌新研究:鲸鱼生物声学模型,可识别8种鲸类
    鲸鱼声音识别对于保护海洋生态具有重要意义,科学家可以通过分析鲸鱼的声音,了解其种类、迁徙路线、繁殖习惯和社会结构,从而制定更加有效的保护政策。然而,鲸鱼声音识别并非易事。首先,目前全世界已知的鲸鱼种类超过94种,且声学频率范围极为广泛,从蓝鲸低至10赫兹的声波到齿鲸高达1......
  • 如何在PbootCMS中实现无刷新点赞功能?
    为了实现Pbootcms的无刷新点赞功能,可以按照以下步骤操作:引入jQuery库:在页面头部引入jQuery库:html <scriptsrc="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>HTML结构:在页面中添加点赞相关的HTML元素:<buttonclass="support">点赞</bu......
  • 民宿酒店预订系统V1.0.10
    多门店民宿酒店预订管理系统,快速部署属于自己民宿酒店的预订小程序,包含预订、退房、WIFI连接、吐槽、周边信息等功能。提供全部无加密源代码,支持私有化部署。V1.0.10修复海报分享错误......
  • 沃德校友会管理系统V1.0.2
    校友会综合服务平台,即校友信息管理平台、活动管理平台、校友服务大厅、校友企业服务平台等,实现集中学校、学院、校友会于一体的基础服务平台的搭建,建设一个满足校友信息化长期发展的、可扩展的综合校友服务平台,提供全部无加密源代码,支持私有化部署。目前Uniapp仅支持编译微信小程序......
  • 智能名片V1.0.6
    在线介绍公司和个人名片,获取客户信息,让客户了解公司产品,尽可能达成成交。V1.0.6安全更新体验优化和代码规范更新1.更新已知bug和体验。2.代码安全更新。......
  • SSM电影网站7u2ji 点赞收藏 点击量推荐
    本系统(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表系统内容:用户,电影信息,电影分类,电影商城,商品分类开题报告内容一、研究背景随着互联网技术的快速发展,电影行业已逐渐向线上转型。电影网站作为电影信息传......