FUXX V2EX || V2EX REDIRECT

Modify all V2EX links to use global.v2ex.co

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         FUXX V2EX || V2EX REDIRECT
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Modify all V2EX links to use global.v2ex.co
// @author       systemoutprintlnhelloworld 
// @match        *://*/*
// @grant        none
// @run-at       document-end
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const DEBUG_MODE = true;

    // 检查并修改链接
    function modifyLinks() {
        // 获取所有链接
        let links = document.querySelectorAll('a[href*="v2ex.com"]');

        // 遍历所有链接
        links.forEach(function(link) {
            // 如果链接包含 .v2ex.com 或 v2ex.com,则替换为 global.v2ex.co
            if (/v2ex\.com/.test(link.href)) {
                let newHref = link.href.replace(/:\/\/(.*\.)?v2ex\.com/, '://global.v2ex.co');
                if (DEBUG_MODE) {
                    console.log(`Modifying link: ${link.href} to ${newHref}`);
                }
                link.href = newHref;
            }
        });
    }

    // 初始修改
    modifyLinks();

    // 监听DOM变化,动态修改新增的链接
    let observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                modifyLinks();
            }
        });
    });

    observer.observe(document.body, { childList: true, subtree: true });
})();