ImageFap picture fixer

changes thumbnail href to full images in galleries on ImageFap, fixing option for those that don't fit pattern, useful for mouseover addons

Από την 14/11/2018. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         ImageFap picture fixer
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  changes thumbnail href to full images in galleries on ImageFap, fixing option for those that don't fit pattern, useful for mouseover addons
// @author       You
// @match        https://www.imagefap.com/pictures/*
// @grant        https://code.jquery.com/jquery-2.2.4.js
// ==/UserScript==

/*
let cache = {};
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);
*/

let uploaderText;
Array.prototype.forEach.call(document.querySelectorAll("b"), function(el) {if (el.innerText.includes("Uploaded by ")) uploaderText = el.innerText.slice(12, el.innerText.length);});


Array.from(document.querySelectorAll("a")).forEach(function(el) {
  if (el.href.split("/")[3] === "photo" && el.parentNode.parentNode.parentNode.children[1].children[0].children[1].innerText.slice(-3) !== "...") {
    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;
  }
});

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>`);


Array.from(document.getElementsByClassName("fixImg")).forEach((el, i) => el.addEventListener("click", function(e) {
  el.innerText = "Fixing...";
  //console.log("url", cache[i]);
  $.ajax({
    type: "GET",
    url: cache[i],
    success: function(data) {
      let newURL = data.match(/https:\/\/x\.imagefapusercontent\.com\/u\/\w+\/\d+\/\d+\/^[.]+\.\w+/);
      if (newURL === null) el.innerText = "Sorry, error!";
      else {
        el.parentNode.parentNode.parentNode.parentNode.children[0].children[0].children[0].href = newURL;
        el.innerText = "Fixed!";
      }
    },
    error: function(data) {
      el.innerText = "Error (hover for info).";
      el.title = data;
    }
  });
}));