IF picture fixer

changes thumbnail href to full images, fixing option for those that don't fit pattern

  1. // ==UserScript==
  2. // @name IF picture fixer
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description changes thumbnail href to full images, fixing option for those that don't fit pattern
  6. // @author You
  7. // @match https://www.imagefap.com/pictures/*
  8. // @grant https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
  9. // ==/UserScript==
  10.  
  11. /*
  12. let cache = {};
  13. Array.from(document.querySelectorAll("font")).filter(el => el.color==="#000000" && el.face==="verdana").forEach((el, i) => cache[i] = el.parentNode.parentNode.parentNode.parentNode.children[0].children[0].children[0].children[0].href);
  14. */
  15.  
  16. let uploaderText;
  17. Array.prototype.forEach.call(document.querySelectorAll("b"), function(el) {if (el.innerText.includes("Uploaded by ")) uploaderText = el.innerText.slice(12, el.innerText.length);});
  18.  
  19.  
  20. Array.from(document.querySelectorAll("a")).forEach(function(el) {
  21. if (el.href.split("/")[3] === "photo" && el.parentNode.parentNode.parentNode.children[1].children[0].children[1].innerText.slice(-3) !== "...") {
  22. el.href = "https://x.imagefapusercontent.com/u/" + uploaderText + "/" + window.location.href.split("/")[4] + "/" + el.href.split("/")[4] + "/" + el.parentNode.parentNode.parentNode.children[1].children[0].innerText;
  23. }
  24. });
  25.  
  26. Array.from(document.querySelectorAll("font")).filter(el => el.color==="#000000" && el.face==="verdana").forEach(el => el.innerHTML += `<br><span class='fixImg'>${el.parentNode.children[1].innerText.slice(-3) === "..." ? "Click here to fix." : "Fixed!"}</span>`);
  27.  
  28.  
  29. Array.from(document.getElementsByClassName("fixImg")).forEach((el, i) => el.addEventListener("click", function(e) {
  30. el.innerText = "Fixing...";
  31. //console.log("url", cache[i]);
  32. $.ajax({
  33. type: "GET",
  34. url: el.parentNode.parentNode.parentNode.parentNode.querySelector("a").href,
  35. success: function(data) {
  36. //let newURL = data.match(/https:\/\/x\.imagefapusercontent\.com\/u\/\w+\/\d+\/\d+\/w+\.\w+/);
  37. let newURL = data.match(/<noscript[\s\S]+<img id="mainPhoto".+src="([^"]+)"/)[1];
  38. if (newURL === null) el.innerText = "Sorry, error!";
  39. else {
  40. el.parentNode.parentNode.parentNode.parentNode.querySelector("a").href = newURL;
  41. el.innerText = "Fixed!";
  42. }
  43. },
  44. error: function(data) {
  45. el.innerText = "Error (hover for info).";
  46. el.title = data;
  47. }
  48. });
  49. }));
  50.