e621 Deleted Post Source Opener

Opens the source or the original post link if the post is deleted (and not a duplicate).

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.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

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         e621 Deleted Post Source Opener
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Opens the source or the original post link if the post is deleted (and not a duplicate).
// @author       Gemini 3
// @match        https://e621.net/posts/*
// @grant        GM_openInTab
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';

    // 1. Проверка на удаление
    const imageContainer = document.querySelector('#image-container');
    const deleteNotice = document.querySelector('.notice-deleted');

    let isDeleted = false;
    if (deleteNotice) {
        isDeleted = true;
    } else if (imageContainer && imageContainer.getAttribute('data-flags')) {
        isDeleted = imageContainer.getAttribute('data-flags').includes('deleted');
    }

    if (!isDeleted) {
        console.log('e621 Deleted Opener: Post is not deleted.');
        return;
    }

    // 2. Проверка причины: не открываем, если это дубликат
    if (deleteNotice) {
        const noticeText = deleteNotice.innerText.toLowerCase();
        if (noticeText.includes('duplicate')) {
             console.log('e621 Deleted Opener: Post is a duplicate. Stopping.');
             return;
        }
    }

    let urlToOpen = null;

    // 3. Пытаемся найти внешнюю ссылку в сайдбаре (Source)
    const externalSourceLinks = document.querySelectorAll('li.source-links .source-link a');
    if (externalSourceLinks.length > 0) {
        urlToOpen = externalSourceLinks[0].href;
        console.log('e621 Deleted Opener: Found external source link.');
    } 
    
    // 4. Если внешнего источника нет (или он не ссылка), ищем внутреннюю ссылку в тексте причины удаления
    if (!urlToOpen && deleteNotice) {
        // Ищем ссылку на другой пост (класс .dtext-post-id-link обычно используется для "post #12345")
        const internalPostLink = deleteNotice.querySelector('a.dtext-post-id-link, a[href^="/posts/"]');
        if (internalPostLink) {
            urlToOpen = internalPostLink.href;
            console.log('e621 Deleted Opener: No external source. Found internal post link in deletion notice.');
        }
    }

    // 5. Открытие ссылки
    if (urlToOpen) {
        console.log(`e621 Deleted Opener: Target found: ${urlToOpen}`);
        setTimeout(() => {
            GM_openInTab(urlToOpen, { active: true });
        }, 500);
    } else {
        console.log('e621 Deleted Opener: No valid source or internal link found.');
    }
})();