Show E-Hentai links on SauceNAO

A userscript that adds E-Hentai (or optionally ExHentai, your choice) links to images SauceNAO got from there originally.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         Show E-Hentai links on SauceNAO
// @description  A userscript that adds E-Hentai (or optionally ExHentai, your choice) links to images SauceNAO got from there originally.
// @namespace    https://easrng.net
// @match        https://saucenao.com/*
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_addValueChangeListener
// @version      1.1
// @author       easrng
// @run-at       document-end
// @download-url https://easrng.github.io/saucenao-ehentai-links/saucenao-ehentai-links.user.js
// @license      be gay do crime
// ==/UserScript==
(function () {
  let useExhentai = Boolean(GM_getValue("useExhentai"));
  for (const img of document.querySelectorAll('img[src*="/ehentai/"]')) {
    const seggs = new URL(img.src).pathname.split("/");
    const hash = seggs[seggs.length - 1].split(".")[0];
    img
      .closest("tr")
      .querySelector(".resultmiscinfo")
      .insertAdjacentHTML(
        "beforeend",
        `<a class="__easrng_eh_link_to_update" href="https://e${
          useExhentai ? "x" : "-"
        }hentai.org/?f_shash=${encodeURIComponent(
          hash
        )}"><img alt="" src="/images/static/siteicons/e-hentai.ico" width="16" height="16" border="0"></a><br><br style="line-height:2px;">`
      );
  }
  let lastMenuId;
  function useExhentaiChanged() {
    for (const link of document.querySelectorAll(
      ".__easrng_eh_link_to_update"
    )) {
      const url = new URL(link.href);
      url.hostname = `e${useExhentai ? "x" : "-"}hentai.org`;
      link.href = url.href;
    }
    const checkbox = (bool) => (bool ? "✔️" : " ");
    if (lastMenuId) GM_unregisterMenuCommand(lastMenuId);
    lastMenuId = GM_registerMenuCommand(
      checkbox(useExhentai) + " Use exhentai.org",
      () => {
        useExhentai = !useExhentai;
        GM_setValue("useExhentai", useExhentai);
      }
    );
  }
  useExhentaiChanged();
  GM_addValueChangeListener(
    "useExhentai",
    (name, oldValue, newValue, remote) => {
      console.log("useExhentai changed from", oldValue, "to", newValue);
      useExhentai = Boolean(newValue);
      useExhentaiChanged();
    }
  );
})();