Restore Removed Posts

Script tries to restore images/videos from removed posts. If post couldn't be restored that means it had been also removed from servers.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Restore Removed Posts
// @version      0.1
// @namespace    liquid5925.scripts
// @description  Script tries to restore images/videos from removed posts. If post couldn't be restored that means it had been also removed from servers.
// @author       liquid5925
// @match        https://rule34.xxx/index.php?page=post&s=view&id=*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=rule34.xxx
// @grant        none
// @license      MIT
// ==/UserScript==

(async function() {
    'use strict';


    const shouldBeExecuted = [...document.getElementsByClassName("status-notice")].filter(e => e.innerText.includes("This post was deleted."));
    if(shouldBeExecuted.length == 0) return;

    const getParams = function() {
        let e = location.search.substr(1).split("&");
        let returnable = {};
        e.forEach(function(r) {
            let ob = r.split("=");
            returnable[ob[0]] = ob[1];
        });
        return returnable;
    }

    const getParam = function(key) {
        let params = getParams();
        return params[key] || null;
    }

    const id = getParam("id");
    let resp;
    try{
        resp = await fetch(`https://api.rule34.xxx/index.php?page=dapi&s=post&q=index&id=${id}&json=1&limit=1`).then(async function(r) { return (await r.json())[0] });
    }catch{
        let text = shouldBeExecuted[0].innerText;
        shouldBeExecuted[0].innerText = `${text}\n[SCRIPT] No file found.`;
    }
    if(!resp) return;
    let file_url = resp.file_url;
    let file_ext = file_url.split(".")[file_url.split(".").length-1];
    let isVideo = ['webm','mp4'].includes(file_ext.toLowerCase());
    let appendable = document.getElementById('fit-to-screen');
    let elem = document.createElement(isVideo ? 'video' : 'img');
    elem.src = file_url;
    if(isVideo){
        elem.loop = true;
        elem.controls = true;
    }
    appendable.prepend(elem);
    shouldBeExecuted[0].remove();
})();