注释很详细,直接上代码
// ==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+fUFCmFu8boAOt1JxnyI7pshV1YlAzi6BTPCDSMtEHU0i38gRexd3dE1fhKsqhOaCpVo2OWulBwJ7QWol4pHSp9tEio9aHpw5kNnAhkjX+yNGESkY5VSFxUjq+aZMttYaU+rOjCi67NdFEEm5QKbhUUo8zl4WJ+AHNIwr5k6Epl8CE2HTPMad1DyyH9Osbj/VRBVUXkMrd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AAAAElFTkSuQmCC
// @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由于学习通风控,眨眼睛做了判断处理,只要有节点未满足要求则会继续进行点赞,直到满足要求,可以忽略警告