V2EX Imgur Proxy

Replace Imgur links with DuckDuckGo proxy on V2EX

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==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
    });
})();