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.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

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