V2EX Imgur Proxy

Replace Imgur links with DuckDuckGo proxy on V2EX

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

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

Tendrás que instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Tendrás que instalar una extensión como Tampermonkey antes de poder instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         V2EX Imgur Proxy
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Replace Imgur links with DuckDuckGo proxy on V2EX
// @author       You
// @match        https://www.v2ex.com/t/*
// @icon         https://www.google.com/s2/favicons?bb=1&domain=v2ex.com
// @grant        none
// @license      MIT License
// ==/UserScript==

(function() {
    'use strict';

    const proxyPrefix = "https://external-content.duckduckgo.com/iu/?u=";

    function replaceImgur() {
        // 1. Handle actual <img> tags
        const images = document.querySelectorAll('img[src*="i.imgur.com"]');
        images.forEach(img => {
            if (!img.src.includes(proxyPrefix)) {
                img.src = proxyPrefix + img.src;
            }
        });

        // 2. Handle <a> links
        const links = document.querySelectorAll('a[href*="i.imgur.com"]');
        links.forEach(link => {
            if (!link.href.includes(proxyPrefix)) {
                link.href = proxyPrefix + link.href;
            }
        });

        // 3. Handle text-only links in posts (V2EX often auto-links these)
        // This looks for elements containing the specific string
        const walker = document.createTreeWalker(document.getElementById('Wrapper'), NodeFilter.SHOW_TEXT, null, false);
        let node;
        while(node = walker.nextNode()) {
            if (node.nodeValue.includes('https://i.imgur.com/') && !node.parentElement.closest('a')) {
                 // If there's raw text not inside a link, this part is harder to replace without
                 // breaking the DOM, but V2EX usually converts these to <a> tags anyway.
            }
        }
    }

    // Run immediately
    replaceImgur();

    // Also run when the content changes (for AJAX loaded replies or previews)
    const observer = new MutationObserver(replaceImgur);
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
})();