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.

  1. // ==UserScript==
  2. // @name Restore Removed Posts
  3. // @version 0.1
  4. // @namespace liquid5925.scripts
  5. // @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.
  6. // @author liquid5925
  7. // @match https://rule34.xxx/index.php?page=post&s=view&id=*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=rule34.xxx
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (async function() {
  14. 'use strict';
  15.  
  16.  
  17. const shouldBeExecuted = [...document.getElementsByClassName("status-notice")].filter(e => e.innerText.includes("This post was deleted."));
  18. if(shouldBeExecuted.length == 0) return;
  19.  
  20. const getParams = function() {
  21. let e = location.search.substr(1).split("&");
  22. let returnable = {};
  23. e.forEach(function(r) {
  24. let ob = r.split("=");
  25. returnable[ob[0]] = ob[1];
  26. });
  27. return returnable;
  28. }
  29.  
  30. const getParam = function(key) {
  31. let params = getParams();
  32. return params[key] || null;
  33. }
  34.  
  35. const id = getParam("id");
  36. let resp;
  37. try{
  38. 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] });
  39. }catch{
  40. let text = shouldBeExecuted[0].innerText;
  41. shouldBeExecuted[0].innerText = `${text}\n[SCRIPT] No file found.`;
  42. }
  43. if(!resp) return;
  44. let file_url = resp.file_url;
  45. let file_ext = file_url.split(".")[file_url.split(".").length-1];
  46. let isVideo = ['webm','mp4'].includes(file_ext.toLowerCase());
  47. let appendable = document.getElementById('fit-to-screen');
  48. let elem = document.createElement(isVideo ? 'video' : 'img');
  49. elem.src = file_url;
  50. if(isVideo){
  51. elem.loop = true;
  52. elem.controls = true;
  53. }
  54. appendable.prepend(elem);
  55. shouldBeExecuted[0].remove();
  56. })();