v2ex 新标签打开

默认使用新标签打开v2ex,而不是在原有网页中打开

// ==UserScript==
// @name         v2ex 新标签打开
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  默认使用新标签打开v2ex,而不是在原有网页中打开
// @author       [email protected]
// @match        https://www.v2ex.com/*
// @license MIT
// @grant        none
// ==/UserScript==
function createProcess() {
    let timer = null;
    return () => {
        if (timer) {
            console.log('clearTimer')
            clearTimeout(timer)
        }
        timer = setTimeout(() => {
            const arr = Array.from(document.querySelectorAll('.topic-link:not([data-done])'))
            arr.forEach(anchor => {
                const href = anchor.getAttribute('href')
                if (!href) return;
                anchor.setAttribute
                anchor.setAttribute('target', '_blank')
                anchor.setAttribute('data-done', 1)
            })
        }, 800)
    }
}
const process = createProcess()

(function() {
    const answersDom = document.querySelector('#Main')
    if (!answersDom) {
        console.log('answer dom not exist!')
        return;
    }
    process()
    const observer = new MutationObserver(function() {
        console.log('observer worked')
        process()
    });
    observer.observe(answersDom, {
        childList: true,
        subtree: true
    });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址