e621 Deleted Post Source Opener

If an e621 post has "status: deleted", this script opens the source URL in a new tab, prioritizing sources other than Inkbunny.

Från och med 2025-07-18. Se den senaste versionen.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         e621 Deleted Post Source Opener
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  If an e621 post has "status: deleted", this script opens the source URL in a new tab, prioritizing sources other than Inkbunny.
// @author       Gemini
// @match        https://e621.net/posts/*
// @grant        GM_openInTab
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';

    // 1. Проверяем, удален ли пост.
    // Ищем элемент списка, содержащий "Status:", и проверяем, есть ли в нем слово "Deleted".
    const infoListItems = document.querySelectorAll('#post-information ul li');
    let isDeleted = false;

    infoListItems.forEach(li => {
        const text = li.innerText.trim();
        if (text.startsWith('Status:') && text.includes('Deleted')) {
            isDeleted = true;
        }
    });

    // Если пост не удален, ничего не делаем.
    if (!isDeleted) {
        console.log('e621 Deleted Opener: Пост не удален.');
        return;
    }

    console.log('e621 Deleted Opener: Пост удален. Ищем источник...');

    // 2. Находим все доступные ссылки на источники.
    const sourceLinkElements = document.querySelectorAll('li.source-links a');
    if (sourceLinkElements.length === 0) {
        console.log('e621 Deleted Opener: Ссылки на источники не найдены.');
        return;
    }

    const allSources = Array.from(sourceLinkElements).map(a => a.href);

    // 3. Отдаем приоритет источникам, не являющимся Inkbunny.
    let preferredSource = null;
    const nonInkbunnySources = allSources.filter(url => !url.includes('inkbunny.net'));

    if (nonInkbunnySources.length > 0) {
        // Найден хотя бы один источник, который не является Inkbunny.
        preferredSource = nonInkbunnySources[0];
        console.log(`e621 Deleted Opener: Выбран источник, не являющийся Inkbunny: ${preferredSource}`);
    } else if (allSources.length > 0) {
        // Других источников нет, поэтому используем первую доступную ссылку.
        preferredSource = allSources[0];
        console.log(`e621 Deleted Opener: Найден только источник Inkbunny (или другой). Используем: ${preferredSource}`);
    }

    // 4. Открываем выбранный источник в новой вкладке.
    if (preferredSource) {
        // Небольшая задержка, чтобы избежать проблем с блокировщиками всплывающих окон.
        setTimeout(() => {
            console.log(`e621 Deleted Opener: Открываем ${preferredSource} в новой вкладке.`);
            GM_openInTab(preferredSource, { active: true });
        }, 500);
    } else {
        console.log('e621 Deleted Opener: Не удалось определить источник для открытия.');
    }
})();