V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  gloria07  ›  全部回复第 1 页 / 共 1 页
回复总数  3
// ==UserScript==
// @name 通用网站协议自动同意助手
// @namespace http://tampermonkey.net/
// @version 1.1
// @description 尝试自动勾选用户协议复选框或点击同意按钮。适用于大多数网站。
// @author YourName
// @match *://*/*
// @grant none
// @run-at document-end
// ==/UserScript==

(function() {
'use strict';

// 策略 1:尝试勾选常见的协议复选框
const checkboxKeywords = ['agreement', 'agree', 'protocol', 'policy', 'terms', 'user-agreement', 'consent'];
const buttonKeywords = ['同意', '同意并继续', '接受', '接受协议', 'agree', 'accept', 'confirm', '允许', '授权', 'consent', 'ok', '下一步', 'next', 'continue'];

function attemptToAgree() {
console.log('通用协议助手:开始尝试自动同意...');

// 策略 1A: 通过属性匹配复选框
let checkboxes = document.querySelectorAll('input[type="checkbox"]');
for (let checkbox of checkboxes) {
let id = checkbox.id.toLowerCase();
let name = checkbox.name.toLowerCase();
let parentText = checkbox.parentElement?.textContent?.toLowerCase() || '';
// 检查是否与协议相关关键词匹配
if (checkboxKeywords.some(keyword => id.includes(keyword) || name.includes(keyword) || parentText.includes(keyword))) {
if (!checkbox.checked) {
checkbox.click();
console.log('通用协议助手:已通过策略 1A (属性匹配)自动勾选复选框。');
// 勾选后不一定立即提交,所以继续执行寻找按钮
break;
}
}
}

// 策略 2: 点击各种类型的“同意”按钮(主要策略)
let allButtons = document.querySelectorAll('button, input[type="button"], input[type="submit"], a.btn, .btn, [role="button"]');
let clicked = false;

for (let button of allButtons) {
let buttonText = (button.textContent || button.value || button.getAttribute('aria-label') || '').trim().toLowerCase();
let buttonClass = button.className.toLowerCase();

// 检查按钮文本是否包含同意关键词
if (buttonKeywords.some(keyword => buttonText.includes(keyword))) {
// 额外检查,确保不是“不同意”或“拒绝”按钮
if (!buttonText.includes('不同意') && !buttonText.includes('拒绝') && !buttonText.includes('disagree') && !buttonText.includes('reject') && !buttonText.includes('cancel')) {
button.click();
console.log('通用协议助手:已通过策略 2 (按钮文本)点击同意按钮。按钮文本:', button.textContent);
clicked = true;
break; // 点击一个后就退出
}
}
}

// 策略 3: 如果没找到明显的按钮,尝试通过表单的提交动作
if (!clicked) {
let forms = document.querySelectorAll('form');
for (let form of forms) {
let formHtml = form.innerHTML.toLowerCase();
// 检查表单内是否包含协议相关文本
if (formHtml.includes('协议') || formHtml.includes('agree') || formHtml.includes('terms')) {
let submitBtn = form.querySelector('button[type="submit"], input[type="submit"]');
if (submitBtn) {
submitBtn.click();
console.log('通用协议助手:已通过策略 3 (表单提交)尝试提交。');
clicked = true;
break;
}
}
}
}

if (!clicked) {
console.log('通用协议助手:本次未找到可自动同意的目标。页面结构可能特殊或已同意。');
}
}

// 使用 MutationObserver 监听 DOM 变化,应对动态加载的页面
const observer = new MutationObserver(function(mutations) {
// 避免频繁执行,设置一个简单的标志
if (!window.agreementHelperTriggered) {
window.agreementHelperTriggered = true;
setTimeout(attemptToAgree, 500); // 延迟半秒执行,确保元素已加载
setTimeout(() => { window.agreementHelperTriggered = false; }, 2000);
}
});

// 开始观察
observer.observe(document.body, {
childList: true,
subtree: true
});

// 页面加载完成后立即尝试一次
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', attemptToAgree);
} else {
setTimeout(attemptToAgree, 1000);
}
})();
2024 年 9 月 18 日
回复了 qq1147 创建的主题 投资 降息还是加息?留下你的预测
我来自未来:听我的猛猛加息
2024 年 3 月 27 日
回复了 pianjiao 创建的主题 微信 微信要打击多开,模拟登录等手段
没 wx 的微信很难用
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   3140 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 17ms · UTC 13:04 · PVG 21:04 · LAX 05:04 · JFK 08:04
♥ Do have faith in what you're doing.