Greasy Fork is available in English.
剪贴板打开链接 + 指定页面自动确认(增强提取版)足够字数才能固定按钮所以保证一下字数足够字数才能固定按钮所以保证一下字数
// ==UserScript==
// @name 全网打开按钮
// @namespace http://tampermonkey.net/
// @version 1.4
// @description 剪贴板打开链接 + 指定页面自动确认(增强提取版)足够字数才能固定按钮所以保证一下字数足够字数才能固定按钮所以保证一下字数
// @match *://*/*
// @grant none
// @license MIT
// ==/UserScript==
(function () {
'use strict';
const KEY_TRIGGER = "ld_auto_click_once";
// ❗ 只在顶层页面运行(防 iframe / hcaptcha)
if (window.top !== window.self) return;
// 屏蔽 hcaptcha
if (location.hostname.includes("hcaptcha")) return;
// ================= 白名单路径 =================
function isAllowedPage(){
const url = location.href;
return (
url.includes("/u/confirm-new-email/") ||
url.includes("/u/confirm-old-email/") ||
url.includes("/u/activate-account/")
);
}
// ================= 提示 =================
function showToast(msg){
let toast = document.getElementById("ld-toast");
if(!toast){
toast = document.createElement("div");
toast.id = "ld-toast";
toast.style.cssText = `
position:fixed;
right:20px;
bottom:120px;
z-index:999999;
background:rgba(0,0,0,0.75);
color:#fff;
padding:10px 14px;
border-radius:8px;
font-size:14px;
`;
document.body.appendChild(toast);
}
toast.innerText = msg;
toast.style.opacity = "1";
setTimeout(()=>toast.style.opacity="0",2000);
}
// ================= 自动点击 =================
function autoHandleButtonsOnce(){
if (!localStorage.getItem(KEY_TRIGGER)) return;
if (!isAllowedPage()){
localStorage.removeItem(KEY_TRIGGER);
return;
}
localStorage.removeItem(KEY_TRIGGER);
showToast("检测目标页面,自动处理中...");
setTimeout(()=>{
let handled = false;
const startTime = Date.now();
const timeout = 10000;
const matchActivate = t => t && (
t.toLowerCase().includes("activate") ||
t.includes("有効") ||
t.includes("激活") ||
t.includes("啟用")
);
const matchConfirm = t => t && (
t.toLowerCase().includes("confirm") ||
t.includes("确认") ||
t.includes("確認")
);
const getButtons = ()=>[
...document.querySelectorAll("button"),
...document.querySelectorAll("[role='button']"),
...document.querySelectorAll(".btn")
];
const timer = setInterval(()=>{
if (Date.now() - startTime > timeout) {
showToast("未找到按钮");
clearInterval(timer);
return;
}
if (handled) return;
const buttons = getButtons();
for(const btn of buttons){
const text = (btn.innerText || "").trim();
if(matchActivate(text)){
handled = true;
btn.click();
showToast("已点击激活");
clearInterval(timer);
return;
}
}
for(const btn of buttons){
const text = (btn.innerText || "").trim();
if(matchConfirm(text)){
handled = true;
btn.click();
showToast("已点击确认");
waitForOk();
clearInterval(timer);
return;
}
}
},500);
function waitForOk(){
const start = Date.now();
const timeout = 15000;
const t2 = setInterval(()=>{
if (Date.now() - start > timeout) {
clearInterval(t2);
return;
}
const buttons = getButtons();
for(const btn of buttons){
const text = (btn.innerText || "").trim().toLowerCase();
if(
text === "ok" ||
text.includes("ok") ||
text.includes("确定") ||
text.includes("確認") ||
text.includes("yes")
){
btn.click();
showToast("已确认弹窗");
clearInterval(t2);
return;
}
}
},300);
}
},1000);
}
// ================= 🔥 强化链接提取 =================
function extractUrls(text){
if (!text) return [];
// 去除零宽字符(关键修复)
text = text.replace(/[\u200B-\u200D\uFEFF]/g, "");
// 替换换行/空格为统一空格
text = text.replace(/\s+/g, " ");
// 提取链接
const matches = text.match(/https?:\/\/[^\s]+/g);
if (!matches) return [];
// 清理末尾可能的符号
return matches.map(url =>
url.replace(/[)\]\}>,,。!?!?.]+$/g, "")
);
}
// ================= 打开按钮 =================
function createOpenBtn(){
if (document.getElementById("ld-open-btn")) return;
const btn = document.createElement("button");
btn.id = "ld-open-btn";
btn.innerText = "打开";
btn.style.cssText = `
position:fixed;
left:20px;
top:20px;
z-index:999999;
padding:10px 16px;
border:none;
border-radius:6px;
background:#9C27B0;
color:#fff;
cursor:pointer;
`;
btn.onclick = async () => {
try {
const text = await navigator.clipboard.readText();
if (!text) return alert("剪贴板为空");
const urls = extractUrls(text);
if (!urls.length) return alert("未检测到链接");
urls.forEach(url => {
localStorage.setItem(KEY_TRIGGER, "1");
window.open(url, "_blank");
});
} catch {
alert("读取剪贴板失败,请允许权限");
}
};
document.body.appendChild(btn);
}
// ================= 启动 =================
createOpenBtn();
let lastUrl = location.href;
setInterval(()=>{
if(location.href !== lastUrl){
lastUrl = location.href;
setTimeout(autoHandleButtonsOnce, 1200);
}
},500);
setTimeout(autoHandleButtonsOnce,1500);
})();