// ==UserScript==
// @name 易班自动发帖网薪经验值
// @namespace https://wechatid.github.io/2024/11/06/Yiban-JSmonkey/
// @version 1.2
// @description 易班自动发贴微社区的脚本,完全自动获取网薪经验值。自动检测内容是否重复,重复即重新输入新的内容内容,易班微社区完全自动发帖脚本,自动获取网薪和经验值
// @match https://s.yiban.cn/userPost/detail
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @grant GM_download
// @license All rights reserved
// ==/UserScript==
(function() {
"use strict";
let sever = 'http://113.45.159.104:8000';
let SIMINPUTFROM_CONNET_AUTOINCREM = 0;
let submits_count = 0;
const panel = document.createElement('div');
panel.id = 'floating-panel';
panel.innerHTML = `
`;
const body = document.body;
body.insertBefore(panel, body.firstChild);
GM_addStyle(`
/* 面板样式 */
#floating-panel {
position: fixed;
top: 30%;
left: 20px;
width: 250px; /* 调整面板宽度 */
background-color: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
z-index: 9999;
font-family: Arial, sans-serif;
transition: all 0.3s ease;
overflow: hidden;
cursor: move; /* 鼠标样式 */
}
#floating-panel .header {
background-color: #007bff;
color: #fff;
padding: 8px;
text-align: center;
border-radius: 8px 8px 0 0;
/* 使用 Flexbox 实现垂直排列 */
display: flex;
flex-direction: column; /* 子元素垂直排列 */
justify-content: center; /* 垂直居中 */
align-items: center; /* 水平居中 */
}
#floating-panel .header h1 {
font-size: 16px;
margin: 0;
}
#floating-panel .toggle-btn {
background-color: #f5f5f5;
border: none;
color: #333;
cursor: pointer;
padding: 5px 8px;
font-size: 12px;
border-radius: 5px;
}
#floating-panel .toggle-btn:hover {
background-color: #ddd;
}
#floating-panel .header .toggle-btn {
margin-top: 8px; /* 为按钮添加上边距,确保按钮与标题有间距 */
}
/* 内容区域 */
#floating-panel .content {
padding: 15px;
display: block;
}
#floating-panel .announcement {
background-color: #e6f7ff;
padding: 8px;
border-radius: 5px;
margin-bottom: 12px;
}
.announcement p {
line-height: 1.3; /* 公告行间距 */
}
#floating-panel .status {
display: flex;
justify-content: space-between;
margin-bottom: 12px;
}
#floating-panel .status-item {
display: flex;
align-items: center;
}
#floating-panel .status-item label {
margin-right: 8px;
font-size: 12px;
}
#floating-panel .status-item input {
width: 60px;
padding: 4px;
text-align: center;
font-size: 12px;
border: 1px solid #ccc;
border-radius: 5px;
}
#floating-panel .key-section {
margin-bottom: 12px;
}
#floating-panel .key-section label {
display: block;
margin-bottom: 5px;
font-size: 12px;
}
#floating-panel .key-section input {
width: 100%;
padding: 6px;
font-size: 12px;
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 10px;
}
#floating-panel .key-section button {
padding: 8px 16px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
#floating-panel .key-section button:hover {
background-color: #0056b3;
}
.button-box {
display: flex;
justify-content: center; /* 水平居中 */
gap: 20px; /* 按钮之间的间隔 */
margin-top: 20px; /* 上部间隔 */
margin-bottom: 20px; /* 下部间隔 */
}
/* 绿色按钮的样式 */
.green-button {
background-color: #1168F4; /* 绿色背景 */
color: white; /* 白色文字 */
border: none; /* 无边框 */
padding: 4px 12px; /* 内边距 */
cursor: pointer; /* 鼠标指针 */
border-radius: 30px; /* 圆角 */
}
/* 橙色按钮的样式 */
.orange-button {
background-color: #2CF411; /* 橙色背景 */
color: white; /* 白色文字 */
border: none; /* 无边框 */
padding: 4px 12px; /* 内边距 */
cursor: pointer; /* 鼠标指针 */
border-radius: 30px; /* 圆角 */
}
/* 鼠标悬停时的效果 */
.green-button:hover, .orange-button:hover {
opacity: 0.8; /* 悬停时稍微透明 */
}
`);
// 实现收起和展开功能
const toggleButton = document.getElementById('toggle-panel');
const contentArea = document.querySelector('.content');
let isCollapsed = false;
toggleButton.addEventListener('click', () => {
if (isCollapsed) {
contentArea.style.display = 'block';
toggleButton.textContent = '收起';
} else {
contentArea.style.display = 'none';
toggleButton.textContent = '展开';
}
isCollapsed = !isCollapsed;
});
// 拖动功能
let isDragging = false;
let offsetX, offsetY;
const panelHeader = document.getElementById('panel-header');
panelHeader.addEventListener('mousedown', (e) => {
isDragging = true;
offsetX = e.clientX - panel.offsetLeft;
offsetY = e.clientY - panel.offsetTop;
panel.style.cursor = 'move';
});
document.addEventListener('mousemove', (e) => {
if (isDragging) {
panel.style.left = `${e.clientX - offsetX}px`;
panel.style.top = `${e.clientY - offsetY}px`;
}
});
document.addEventListener('mouseup', () => {
isDragging = false;
panel.style.cursor = 'move';
});
// 从 localStorage 中读取保存的 API Key
let savedKey = localStorage.getItem('apiKey');
if (savedKey) {
// 如果有保存的API Key,将其填充到输入框
document.getElementById('api-key').value = savedKey;
} else {
document.getElementById('api-key').placeholder = "暂未填写你的卡密";
}
// 获取确认按钮并添加事件监听器
document.getElementById('submit-btn').addEventListener('click', function() {
// 获取用户输入的 API Key
const apiKey = document.getElementById('api-key').value;
if (apiKey) {
// 存储用户输入的 API Key 到 localStorage
localStorage.setItem('apiKey', apiKey);
savedKey = localStorage.getItem('apiKey');
document.getElementById('api-key').value = savedKey;
alert('卡密已保存,请妥善保管,清除缓存会丢失卡密信息!刷新页面即可开始');
} else {
//alert('请输入有效的API Key');
}
});
let input = document.getElementById('remaining');
GM_xmlhttpRequest({
method: 'GET',
url: sever + '/check_counter?key=' + savedKey,
headers: {
'Accept': 'application/json'
},
onload: function(r) {
if (r.status === 200) {
try {
const j = JSON.parse(r.responseText);
input.value = j.counter;
} catch (e) {
input.value = '响应解析失败';
}
} else {
input.value = '卡密不存在';
}
},
onerror: function() {
input.value = '请求失败';
}
});
function simulateComplexClick(element, offsetX, offsetY) {
let rect = element.getBoundingClientRect();
let click_x = rect.left + offsetX;
let click_y = rect.top + offsetY;
["mousedown", "mouseup", "click", /* "touchstart"*/ ].forEach((eventType) => {
var clickEvent = new MouseEvent("mousedown", {
bubbles: true,
cancelable: true,
view: unsafeWindow,
clientX: click_x,
clientY: click_y,
});
element.dispatchEvent(clickEvent);
let td;
let td_s = setInterval(() => {
//发帖成功之后的页面按钮
td = document.querySelector("body > div.container > section > div.mdc-alert.mdc-alert--success > div");
if (td == null) {
console.log('检测不到');
verify();
clearInterval(td_s);
}
clearInterval(td_s);
}, 4000);
});
}
function waitForElement(selector, timeout = 3000) {
return new Promise((resolve, reject) => {
const startTime = Date.now();
// 定时器检查元素是否存在
const msgIsRepeat_int = setInterval(() => {
const msgIsRepeat = document.querySelector(selector);
if (msgIsRepeat) {
clearInterval(msgIsRepeat_int); // 找到元素时清除定时器
resolve(msgIsRepeat); // 返回元素
}
// 如果超过指定的时间还没找到元素
if (Date.now() - startTime > timeout) {
clearInterval(msgIsRepeat_int); // 超时时清除定时器
reject(new Error(`Element not found within ${timeout} ms`)); // 返回超时错误
}
}, 200); // 每100毫秒检查一次
});
}
window.simulateComplexClick = simulateComplexClick
let bg_url = ''; // 全局状态变量,存储背景图 URL
let interval; // 用于保存定时器引用
function verify() {
// 清除之前的定时器
if (interval) {
clearInterval(interval);
}
setTimeout(() => {
interval = setInterval(() => {
//let element = document.querySelector('.shumei_captcha_loaded_img_bg');
let base_dom = document.querySelector("body").lastChild.childNodes[1].childNodes[0];
waitForElement('body > div.mdc-confirm-dialog.mdc-dialog.mdc-dialog--open > div.mdc-dialog__container > div > footer > button.mdc-button.mdc-button--outlined.mdc-confirm-dialog__secondary-button')
.then(msgIsRepeat => {
console.log('Element found:', msgIsRepeat);
clearInterval(interval);
msgIsRepeat.click();
SIMINPUTFROM_CONNET_AUTOINCREM--;
edit_text();
return;
// 在这里处理找到的元素
})
.catch(error => {
console.log(error.message);
// 处理没有找到元素的情况(比如超时)
});
let element = base_dom.childNodes[0].childNodes[2].firstChild.firstChild;
let msgIsRepeat;
// msgIsRepeat = document.querySelector("body > div.mdc-confirm-dialog.mdc-dialog.mdc-dialog--open > div.mdc-dialog__container > div > footer > button.mdc-button.mdc-button--outlined.mdc-confirm-dialog__secondary-button");
if (element) {
console.log("333");
// 检查 src 是否更新
if (element.src.indexOf('https') !== -1 && bg_url !== element.src) {
clearInterval(interval); // 清除定时器,防止重复执行
bg_url = element.src; // 更新 bg_url
GM_xmlhttpRequest({
method: 'GET',
url: sever + '/predict?key=' + savedKey + '&bg_img=' + encodeURIComponent(element.src),
headers: {
'Accept': 'application/json'
},
onload: function(r) {
if (r.status === 200) {
try {
const j = JSON.parse(r.responseText);
if (j['reply'] === 'success') {
simulateComplexClick(base_dom.childNodes[0].childNodes[2].firstChild.firstChild, j['position']['X'] / 2, j['position']['Y'] / 2);
input.value = j['counter'];
} else {
alert('次数不够');
}
} catch (e) {
alert('响应解析失败');
}
} else {
alert('卡密或者服务器错误');
}
},
onerror: function() {
alert('请求失败');
}
});
}
}
}, 100);
}, 100);
}
window.edit_text = function() {
fetch("https://v1.hitokoto.cn/")
.then((response) => response.json())
.then((data) => {
let info_text = data.hitokoto;
let from = data.from;
let author = data.from_who;
let input_1 = document.querySelector(
"body > div.container > section > div.mdc-form.mdc-form--horizontal > div:nth-child(1) > div > input"
);
let input_2 = document.querySelector(
"body > div.container > section > div.mdc-form.mdc-form--horizontal > div:nth-child(2) > div > span.mdc-text-field__resizer > textarea"
);
let connet = document.getElementById(
"ueditor_" + SIMINPUTFROM_CONNET_AUTOINCREM + ""
).contentWindow.document.querySelector("body > p");
let submit_btn = document.querySelector(
"body > div.container > section > div.actions > div > button:nth-child(2) > div"
);
input_1.value = info_text;
input_2.value = info_text;
connet.innerHTML = "