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.

Tính đến 03-10-2022. Xem phiên bản mới nhất.

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

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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