- Created new Tampermonkey script to automatically skip Alt text confirmation modal on Mastodon - Auto-detects and clicks "就这样发布" button when posting images without alt text - Uses MutationObserver for efficient DOM monitoring - Updated README with script documentation and usage instructions
67 lines
2.1 KiB
JavaScript
67 lines
2.1 KiB
JavaScript
// ==UserScript==
|
|
// @name Mastodon 自动跳过图片 Alt 提示
|
|
// @namespace http://tampermonkey.net/
|
|
// @version 1.0.0
|
|
// @description 在 Mastodon 发送带图片的消息时自动跳过 Alt 文本提示弹窗
|
|
// @author Your Name
|
|
// @match https://nofan.xyz/*
|
|
// @grant none
|
|
// @run-at document-end
|
|
// ==/UserScript==
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
console.log('Mastodon Alt Modal Skipper 已加载');
|
|
|
|
// 自动点击"就这样发布"按钮
|
|
function autoClickConfirm() {
|
|
// 查找所有按钮
|
|
const buttons = document.querySelectorAll('button');
|
|
|
|
for (const button of buttons) {
|
|
const buttonText = button.textContent.trim();
|
|
|
|
// 精确匹配"就这样发布"按钮
|
|
if (buttonText === '就这样发布') {
|
|
console.log('找到"就这样发布"按钮,自动点击');
|
|
button.click();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// 监听 DOM 变化,检测模态框出现
|
|
const observer = new MutationObserver(function(mutations) {
|
|
for (const mutation of mutations) {
|
|
if (mutation.addedNodes.length) {
|
|
// 检查是否有新增的按钮包含"就这样发布"文字
|
|
const buttons = document.querySelectorAll('button');
|
|
|
|
for (const button of buttons) {
|
|
if (button.textContent.trim() === '就这样发布') {
|
|
console.log('检测到 Alt 文本提示模态框');
|
|
|
|
// 稍微延迟以确保按钮完全可点击
|
|
setTimeout(() => {
|
|
autoClickConfirm();
|
|
}, 100);
|
|
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// 开始观察整个 body
|
|
observer.observe(document.body, {
|
|
childList: true,
|
|
subtree: true
|
|
});
|
|
|
|
console.log('Mastodon Alt Modal Skipper 初始化完成,等待"就这样发布"按钮出现');
|
|
})();
|