// ==UserScript==
// @name 小码王Plus
// @version 1.3.0
// @description 使你的小码王更易于使用
// @author 红石镐&Copilot
// @match https://world.xiaomawang.com/*
// @icon https://world.xiaomawang.com/favicon.ico
// @license MIT
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// @require https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.all.min.js
// @namespace https://gf.qytechs.cn/users/1254226
// ==/UserScript==
(function () {
'use strict';
// 创建一个遮罩层并追加到 body
const overlay = document.createElement('div');
overlay.style.position = 'fixed';
overlay.style.top = '0';
overlay.style.left = '0';
overlay.style.width = '100%';
overlay.style.height = '100%';
overlay.style.backgroundColor = 'rgba(255, 255, 255, 1)'; // 白色遮罩,不透明
overlay.style.zIndex = '9999'; // 确保遮罩层在最上面
overlay.style.display = 'flex';
overlay.style.flexDirection = 'column'; // 垂直排列
overlay.style.alignItems = 'center';
overlay.style.justifyContent = 'center';
overlay.style.opacity = '0'; // 初始不透明度为 0
overlay.style.transition = 'opacity 0.5s ease'; // 设置淡入淡出效果
// 创建加载指示器
const spinner = document.createElement('div');
spinner.style.width = '50px'; // 指示器的宽度
spinner.style.height = '50px'; // 指示器的高度
spinner.style.border = '5px solid #007bff'; // 边框颜色
spinner.style.borderTop = '5px solid transparent'; // 顶部边框透明
spinner.style.borderRadius = '50%'; // 圆形
spinner.style.animation = 'spin 1s linear infinite'; // 添加旋转动画
// 添加加载动画的 CSS
const style = document.createElement('style');
style.innerHTML = `
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
`;
document.head.appendChild(style);
// 创建文本节点
const loadingText = document.createElement('div');
loadingText.innerText = '小码王Plus加载中...'; // 加载文本
loadingText.style.marginTop = '10px'; // 指示器与文本之间的间距
loadingText.style.fontSize = '16px'; // 字体大小
loadingText.style.color = '#007bff'; // 文本颜色(可选的样式)
// 将指示器和文本添加到遮罩层
overlay.appendChild(spinner);
overlay.appendChild(loadingText);
document.body.appendChild(overlay);
// 淡入效果
setTimeout(() => {
overlay.style.opacity = '1'; // 设置为完全可见
}, 0); // 0 毫秒延迟以确保立即执行
// 初始化设置
const settings = {
autoReceive: GM_getValue('autoReceive', true),// 自动领取奖励
autoSignIn: GM_getValue('autoSignIn', true),// 自动签到
autoLoadComments: GM_getValue('autoLoadComments', true),// 自动展开评论
autoExpandReplies: GM_getValue('autoExpandReplies', false),// 自动展开子回复
autoClickMore: GM_getValue('autoClickMore', true),//自动点击个人主页中查看更多按钮
messageDoNotDisturb: GM_getValue('messageDoNotDisturb', false),// 消息免打扰
removeDynamicRedDot: GM_getValue('removeDynamicRedDot', false),// 动态免打扰
removeAvatarFrame: GM_getValue('removeAvatarFrame', false),// 移除头像框
removeMagicReview: GM_getValue('removeMagicReview', false),// 移除右下角魔力测评
};
// 注册(不可用)设置菜单命令
GM_registerMenuCommand('设置', openSettingsDialog);
function openSettingsDialog() {
Swal.fire({
title: '设置',
html: `
<style>
/* 样式定义 */
.custom-confirm-button {
background-color: #007bff !important; /* 确认按钮颜色 */
color: white !important; /* 确认按钮字体颜色 */
border-radius: 8px; /* 按钮圆角 */
}
.custom-confirm-button:hover {
background-color: #0056b3 !important; /* 悬停时的颜色 */
}
.custom-cancel-button {
background-color: #ccc; /* 取消按钮颜色 */
color: white; /* 字体颜色 */
border-radius: 8px; /* 按钮圆角 */
}
.custom-cancel-button:hover {
background-color: #bbb; /* 悬停时的颜色 */
}
/* 其他勾选框样式 */
.custom-checkbox {
display: flex;
align-items: center;
margin-bottom: 15px; /* 增加标签间距 */
}
.custom-checkbox input[type="checkbox"] {
appearance: none; /* 关闭默认样式 */
width: 24px; /* 自定义勾选框大小 */
height: 24px; /* 自定义勾选框大小 */
border: 2px solid #007bff; /* 勾选框边框 */
border-radius: 4px; /* 勾选框圆角 */
outline: none; /* 关闭默认高亮 */
cursor: pointer; /* 鼠标手势 */
position: relative; /* 设为相对定位 */
margin-right: 10px; /* 标签和勾选框间隔 */
transition: background-color 0.3s, border-color 0.3s; /* 动效 */
}
.custom-checkbox input[type="checkbox"]:checked {
background-color: #007bff; /* 勾选框背景颜色 */
border-color: #007bff; /* 选中后的边框颜色 */
}
.custom-checkbox input[type="checkbox"]:checked::before {
content: '✔'; /* 勾选后显示的符号 */
position: absolute;
left: 50%; /* 符号水平居中 */
top: 50%; /* 符号垂直居中 */
transform: translate(-50%, -50%); /* 调整符号位置 */
color: white; /* 符号颜色 */
font-size: 18px; /* 符号大小 */
}
</style>
<label class="custom-checkbox">
<input type="checkbox" name="autoReceive" ${settings.autoReceive ? 'checked' : ''}> 自动领取奖励
</label><br/>
<label class="custom-checkbox">
<input type="checkbox" name="autoSignIn" ${settings.autoSignIn ? 'checked' : ''}> 自动签到
</label><br/>
<label class="custom-checkbox">
<input type="checkbox" name="autoLoadComments" ${settings.autoLoadComments ? 'checked' : ''}> 自动展开评论
</label><br/>
<label class="custom-checkbox">
<input type="checkbox" name="autoExpandReplies" ${settings.autoExpandReplies ? 'checked' : ''}> 自动展开子回复
</label><br/>
<label class="custom-checkbox">
<input type="checkbox" name="autoClickMore" ${settings.autoClickMore ? 'checked' : ''}> 自动点击查看更多
</label><br/>
<label class="custom-checkbox">
<input type="checkbox" name="messageDoNotDisturb" ${settings.messageDoNotDisturb ? 'checked' : ''}> 消息免打扰
</label><br/>
<label class="custom-checkbox">
<input type="checkbox" name="removeDynamicRedDot" ${settings.removeDynamicRedDot ? 'checked' : ''}> 动态免打扰
</label><br/>
<label class="custom-checkbox">
<input type="checkbox" name="removeAvatarFrame" ${settings.removeAvatarFrame ? 'checked' : ''}> 移除头像框
</label><br/>
<label class="custom-checkbox">
<input type="checkbox" name="removeMagicReview" ${settings.removeMagicReview ? 'checked' : ''}> 移除右下角魔力测评
</label><br/>
`,
showCancelButton: true,
confirmButtonText: '保存',
cancelButtonText: '取消',
customClass: {
confirmButton: 'custom-confirm-button',
cancelButton: 'custom-cancel-button'
},
preConfirm: () => {
settings.autoReceive = document.querySelector('input[name="autoReceive"]').checked; // 获取领取奖励状态
settings.autoSignIn = document.querySelector('input[name="autoSignIn"]').checked; // 获取签到状态
settings.autoLoadComments = document.querySelector('input[name="autoLoadComments"]').checked; // 获取展开评论状态
settings.autoExpandReplies = document.querySelector('input[name="autoExpandReplies"]').checked; // 获取展开子回复状态
settings.autoClickMore = document.querySelector('input[name="autoClickMore"]').checked; // 获取查看更多按钮状态
settings.messageDoNotDisturb = document.querySelector('input[name="messageDoNotDisturb"]').checked; // 获取免打扰状态
settings.removeDynamicRedDot = document.querySelector('input[name="removeDynamicRedDot"]').checked; // 获取动态免打扰状态
settings.removeAvatarFrame = document.querySelector('input[name="removeAvatarFrame"]').checked; // 获取移除头像框状态
settings.removeMagicReview = document.querySelector('input[name="removeMagicReview"]').checked; // 获取移除魔力测评状态
GM_setValue('autoReceive', settings.autoReceive); // 保存领取奖励状态
GM_setValue('autoSignIn', settings.autoSignIn); // 保存签到状态
GM_setValue('autoLoadComments', settings.autoLoadComments); // 保存展开评论状态
GM_setValue('autoExpandReplies', settings.autoExpandReplies); // 保存展开子回复状态
GM_setValue('autoClickMore', settings.autoClickMore); // 保存查看更多按钮状态
GM_setValue('messageDoNotDisturb', settings.messageDoNotDisturb); // 保存免打扰状态
GM_setValue('removeDynamicRedDot', settings.removeDynamicRedDot); // 保存动态免打扰状态
GM_setValue('removeAvatarFrame', settings.removeAvatarFrame); // 保存移除头像框状态
GM_setValue('removeMagicReview', settings.removeMagicReview); // 保存移除魔力测评状态
return Swal.fire({
title: '设置已保存',
text: '更改的设置需刷新后生效,是否刷新?',
showCancelButton: true,
confirmButtonText: '刷新',
cancelButtonText: '取消',
customClass: {
confirmButton: 'custom-confirm-button', // 自定义确认按钮类
cancelButton: 'custom-cancel-button' // 自定义取消按钮类
}
}).then((result) => {
if (result.isConfirmed) {
window.location.reload();
}
});
}
});
}
// 当页面加载完成后开始执行功能并移除遮罩层
window.onload = function() {
// 自动领取奖励的代码...
if (settings.autoReceive) {
function clickReceive() {
var receiveButton = document.querySelector("div.taskAction__3nOcF.taskReceiveReward__16CiZ");
if (receiveButton && receiveButton.textContent === "领取") {
receiveButton.click();
}
}
// 持续检查领取奖励元素是否存在
setInterval(function() {
clickReceive(); // 如果找到元素则执行领取
}, 1000);
}
// 自动签到的代码...
if (settings.autoSignIn) {
setTimeout(function() {
if (window.location.href.includes('/w/index')) {
var signInButton = document.evaluate("//div [@class='goTaskCenter__h4wru' and text()='签到']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (signInButton) {
function clickSignInButton() {
if (document.body.textContent.includes("已领取")) {
clearInterval(signInInterval);
} else {
signInButton.click();
}
}
var signInInterval = setInterval(clickSignInButton, 1000);
}
}
}, 4000); // 等待网页加载4秒后执行
}
// 自动展开评论的代码...
if (settings.autoLoadComments) {
setInterval(function() {
var moreCommentsButton = document.querySelector('span.iconfont.icon-shequ-xiala.more-comment-icon__2Bxj9');
if (moreCommentsButton) {
moreCommentsButton.click();
}
}, 1000);
}
// 自动展开子回复的代码...
if (settings.autoExpandReplies) {
setInterval(function() {
var replyMoreButton = document.evaluate("//span[contains(@class, 'reply-more-button-text__iB2jQ')]", document, null, XPathResult.ANY_TYPE, null);
var button = replyMoreButton.iterateNext();
while (button) {
button.click();
button = replyMoreButton.iterateNext();
}
}, 1000);
}
// 自动点击个人主页中查看更多按钮
if (settings.autoClickMore) {
setInterval(function() {
// 检查是否存在 "查看更多" 按钮
var seeMoreButton = document.querySelector('.seeMore__1QtpQ');
if (seeMoreButton && seeMoreButton.textContent.trim() === "查看更多") {
seeMoreButton.click(); // 点击按钮
}
}, 1000);
}
// 消息免打扰功能
if (settings.messageDoNotDisturb) {
setInterval(function() {
var messageCountElement = document.querySelector('.message-count__2M-on');
if (messageCountElement) {
messageCountElement.remove(); // 删除消息计数元素
}
}, 1000);
}
// 动态免打扰功能
if (settings.removeDynamicRedDot) {
setInterval(function() {
var dynamicRedDotElement = document.querySelector('.dynamic-red-dot__3FSaW');
if (dynamicRedDotElement) {
dynamicRedDotElement.remove(); // 删除动态红点元素
}
}, 1000);
}
// 移除头像框功能
if (settings.removeAvatarFrame) {
setInterval(function() {
// 移除 headDecoration__3FOFH 元素
var avatarFrameElement = document.querySelector('.headDecoration__3FOFH');
if (avatarFrameElement) {
avatarFrameElement.remove(); // 删除头像框元素
}
// 移除 decorationImg__76Jm7 元素
var decorationImgElement = document.querySelector('.decorationImg__76Jm7');
if (decorationImgElement) {
decorationImgElement.remove(); // 删除头像框元素
}
}, 1000);
}
// 移除魔力测评功能
if (settings.removeMagicReview) {
setInterval(function() {
//移除 outer__3SbsJ 元素
var outerElement = document.querySelector('.outer__3SbsJ');
if (outerElement) {
outerElement.remove(); // 删除魔力测评元素
}
}, 1000);
}
// 使用 setTimeout 等待1秒再移除遮罩层
setTimeout(() => {
overlay.style.opacity = '0'; // 开始淡出
setTimeout(() => {
overlay.remove(); // 完全透明后移除遮罩层
}, 500); // 等待过渡时间再移除
}, 1000); // 等待1秒再淡出
};
})();