e621 Deleted Post Source Opener

If an e621 post has "status: deleted", this script opens the first available source URL in a new tab.

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 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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

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

(function() {
    'use strict';

    // 1. Check if the post is deleted.
    // The most reliable way on the new e621 is to check for the presence of the 'notice-deleted' class 
    // or an attribute in the #image-container.
    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;
    }

    console.log('e621 Deleted Opener: Post is deleted. Searching for source...');

    // 2. Look for source links.
    // On e621, links are located inside li.source-links. 
    // We take only those that lead to external sites (excluding the "Source:" text).
    const sourceLinks = document.querySelectorAll('li.source-links .source-link a');

    if (sourceLinks.length > 0) {
        const firstSource = sourceLinks[0].href;
        console.log(`e621 Deleted Opener: Source found: ${firstSource}`);

        // Small delay to bypass popup blockers.
        setTimeout(() => {
            console.log(`e621 Deleted Opener: Opening ${firstSource} in a new tab.`);
            GM_openInTab(firstSource, { active: true });
        }, 500);
    } else {
        console.log('e621 Deleted Opener: Source links not found.');
    }
})();