ehentai better experience

zh Discuz for better experience

As of 2021-04-09. See the latest version.

// ==UserScript==
// @name          ehentai better experience
// @namespace discuz
// @description zh Discuz for better experience
// @include        http*://exhentai.org/*
// @require      https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js
// @version 1.2
// ==/UserScript==

if (/\/g\//.test(location.pathname)) {
  var xpath = "//div[@class='gt' or @class='gtl']/a[@onclick]";
  var nodes = document.evaluate(
    xpath,
    document,
    null,
    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
    null
  );
  var node = null;
  var index = 0;
  while ((node = nodes.snapshotItem(index))) {
    node.removeAttribute("onclick");
    index++;
  }

  var fav_url = popbase + "addfav";

  function fav_post() {
    if (
      document.getElementById("favoritelink").textContent == " Add to Favorites"
    ) {
      $.post(fav_url, {
        favcat: "0",
        favnote: "",
        apply: "Add to Favorites",
        update: "1",
      }).done(function () {
        if (document.getElementById("favoritelink") != undefined) {
          document.getElementById("fav").innerHTML =
            '<div class="i" style="background-image:url(https://exhentai.org/img/fav.png); background-position:0px -2px; margin-left:10px" title="Favorites 0"></div>';
          document.getElementById("favoritelink").innerHTML = "Favorites 0";
        }
      });
    } else {
      $.post(fav_url, {
        favcat: "favdel",
        favnote: "",
        apply: "Apply Changes",
        update: "1",
      }).done(function () {
        if (document.getElementById("favoritelink") != undefined) {
          document.getElementById("fav").innerHTML = "";
          document.getElementById("favoritelink").innerHTML =
            '<img src="https://exhentai.org/img/mr.gif" /> Add to Favorites';
        }
      });
    }
  }

  var gdf_div = document.querySelector("#gdf");
  gdf_div.removeAttribute("onclick");
  gdf_div.addEventListener("click", fav_post, false);
}

if (/(\/g\/)|(watched)|(popular)|(favorites)/.test(location.pathname)) {
  var nb_div = document.querySelector("#nb");

  function createElementFromHTML(htmlString) {
    var div = document.createElement("div");
    div.innerHTML = htmlString.trim();

    // Change this to div.childNodes to support multiple top-level nodes
    return div.firstChild;
  }

  function global_search() {
    var s_content = document.getElementById("g_search");
    window.location.href = "/?f_search=" + s_content.value; //relative to domain
  }

  var html_string =
    '<p class="nopm"><input type="text" id="g_search" name="g_search" placeholder="Search Keywords" size="50" maxlength="200"><input type="submit" id="g_search_btn" value="Apply Filter"></p>';
  var search_bar = createElementFromHTML(html_string);
  nb_div.appendChild(search_bar);

  var g_search_btn = document.querySelector("#g_search_btn");
  g_search_btn.addEventListener("click", global_search, false);

  !(function nb_css_mod() {
    var style = "<style> #nb:hover { max-height: 46px;} </style>";
    // var $userBgStyle = $("#user_bg_theme");
    $("head").append(style);
  })();
}

var title_path = "//div[contains(@class, 'gl4t')]";
var titles = document.evaluate(
    title_path,
    document,
    null,
    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
    null
);
var title = null;
var idx = 0;
while ((title = titles.snapshotItem(idx))) {
    var text = title.innerText;
    if (text.includes("中国翻訳")) {
      title.setAttribute("style", "color: #69cde2;");}
    idx++;
}