// ==UserScript==
// @name XY自动提交
// @namespace http://tampermonkey.net/
// @version 1.1
// @description 自动填写跟进备注并提交表单,不跳转不弹窗
// @author You
// @match https://hw.jst2024.cn/web/2024/*
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
// 屏蔽所有弹窗
window.alert = function() { return true; };
window.confirm = function() { return true; };
window.prompt = function() { return ''; };
window.onbeforeunload = null;
window.onunload = null;
// 脚本开关状态(从缓存读取)
let scriptEnabled = localStorage.getItem('scriptEnabled') !== 'false';
// 创建控制框
function createControlBox() {
const controlBox = document.createElement('div');
controlBox.id = 'script-control-box';
controlBox.style.cssText = 'position:fixed;top:10px;right:10px;background:#fff;border:1px solid #ccc;padding:5px;z-index:999999;';
// 根据当前状态初始化按钮文字
const initBtnText = scriptEnabled ? '停止' : '启动';
const initStatusText = scriptEnabled ? '运行中' : '已停止';
controlBox.innerHTML = `
${initStatusText}
监控中
`;
document.body.appendChild(controlBox);
// 绑定事件
const toggleBtn = document.getElementById('toggle-btn');
const statusText = document.getElementById('status-text');
const currentStatus = document.getElementById('current-status');
toggleBtn.addEventListener('click', function() {
scriptEnabled = !scriptEnabled;
// 保存到缓存
localStorage.setItem('scriptEnabled', scriptEnabled);
if (scriptEnabled) {
toggleBtn.textContent = '停止';
statusText.textContent = '运行中';
currentStatus.textContent = '监控中';
} else {
toggleBtn.textContent = '启动';
statusText.textContent = '已停止';
currentStatus.textContent = '已暂停';
}
});
return controlBox;
}
// 自动填写并提交表单
function autoFillAndSubmit() {
if (!scriptEnabled) return;
const currentStatus = document.getElementById('current-status');
if (currentStatus) currentStatus.textContent = '填写中';
setTimeout(function() {
try {
var contentInput = document.querySelector('input[name="content"]');
if (contentInput) {
if (currentStatus) currentStatus.textContent = '提交中';
contentInput.value = '1';
contentInput.setAttribute('value', '1');
contentInput.dispatchEvent(new Event('input', { bubbles: true }));
contentInput.dispatchEvent(new Event('change', { bubbles: true }));
setTimeout(function() {
var form = document.querySelector('form');
if (form) {
try {
var formData = new FormData(form);
formData.set('content', '1');
fetch(form.action || window.location.href, {
method: 'POST',
body: formData,
keepalive: true
}).catch(function() {});
setTimeout(function() {
try {
var submitBtn = document.querySelector('input[type="submit"]');
if (submitBtn) {
submitBtn.click();
if (currentStatus) currentStatus.textContent = '完成';
}
} catch (e) {}
}, 50);
} catch (e) {}
}
}, 50);
}
} catch (error) {}
}, 200);
}
// 等待页面加载
function waitForPage() {
if (!document.getElementById('script-control-box')) {
createControlBox();
}
if (window.location.href.includes('private_edit.php')) {
const currentStatus = document.getElementById('current-status');
if (currentStatus) currentStatus.textContent = '编辑页';
autoFillAndSubmit();
} else {
const currentStatus = document.getElementById('current-status');
if (currentStatus) currentStatus.textContent = '监控中';
}
}
// 页面加载完成后执行
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', waitForPage);
} else {
waitForPage();
}
// 监听页面变化
let lastUrl = location.href;
new MutationObserver(() => {
if (location.href !== lastUrl && location.href.includes('private_edit.php')) {
lastUrl = location.href;
setTimeout(autoFillAndSubmit, 200);
}
}).observe(document, {subtree: true, childList: true});
})();