// ==UserScript==// @name         Nodeseek Helper// @name:zh-CN   Nodeseek 助手 (外链直达 + 快捷回复)// @namespace    https://github.com/google-gemini-assistant// @version      2.1// @description  1. Rewrites external links to be direct. 2. Adds Ctrl+Enter shortcut to submit comments.// @description:zh-CN  1. 自动重写网站外链,跳过跳转提示,实现链接直达。 2. 在帖子回复框中,可以使用快捷键 Ctrl+Enter (Cmd+Enter) 来快速发布评论。// @author       Gemini// @match        https://www.nodeseek.com/*// @exclude      https://www.nodeseek.com/jump?to=*// @grant        none// @run-at       document-idle// ==/UserScript==(function() {    'use strict';    // --- 功能一:外链直接跳转 (来自之前的脚本) ---    const rewriteLinks = (node) => {        if (node.nodeType !== 1) return;        const links = node.querySelectorAll('a[href*="/jump?to="]');        links.forEach(link => {            try {                const urlObj = new URL(link.href);                const destinationUrl = urlObj.searchParams.get('to');                if (destinationUrl) {                    link.href = destinationUrl;                }            } catch (e) {                console.error('Nodeseek Helper script failed to parse URL:', link.href, e);            }        });    };    // 页面加载后执行一次链接替换    rewriteLinks(document.body);    // 使用 MutationObserver 监听并处理动态加载的内容    const observer = new MutationObserver((mutationsList) => {        for (const mutation of mutationsList) {            if (mutation.type === 'childList') {                mutation.addedNodes.forEach(node => rewriteLinks(node));            }        }    });    observer.observe(document.body, { childList: true, subtree: true });    console.log('Nodeseek Helper: Direct links enabled.');    // --- 功能二:Ctrl+Enter 快捷回复 ---    const setupShortcutListener = () => {        document.addEventListener('keydown', (event) => {            // 检查是否按下了 Ctrl+Enter (Windows/Linux) 或 Cmd+Enter (Mac)            if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {                const activeEl = document.activeElement;                // 确认当前焦点在文本输入区 (textarea 或可编辑的div)                const isTypingInEditor = activeEl && (activeEl.tagName === 'TEXTAREA' || activeEl.isContentEditable);                if (isTypingInEditor) {                    // 寻找与当前输入框关联的“发布评论”按钮                    // 优先在其最近的 <form> 父元素里找,这样最准确                    const form = activeEl.closest('form');                    let submitButton = null;                    if (form) {                        submitButton = Array.from(form.querySelectorAll('button')).find(btn => btn.textContent.trim() === '发布评论');                    }                    // 如果在 form 中没找到,则在整个页面里寻找,作为备用方案                    if (!submitButton) {                        submitButton = Array.from(document.querySelectorAll('button')).find(btn => btn.textContent.trim() === '发布评论');                    }                    if (submitButton) {                        // 阻止默认行为(如在文本框中换行)                        event.preventDefault();                        // 模拟点击按钮                        submitButton.click();                    }                }            }        });        console.log('Nodeseek Helper: Ctrl+Enter shortcut enabled.');    };    // 启动快捷键监听    setupShortcutListener();})();