find panda

check panda.chaika.moe for related galleries when searching

Verzia zo dňa 02.12.2022. Pozri najnovšiu verziu.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

// ==UserScript==
// @name find panda
// @namespace http://tampermonkey.net/
// @version 0.1
// @description check panda.chaika.moe for related galleries when searching
// @description:zh 在搜索时检查panda.chaika.moe里是否有相关的画廊
// @author ayasetan
// @license MIT
// @icon https://www.google.com/s2/favicons?sz=64&domain=e-hentai.org
// @run-at document-start
// @match https://exhentai.org/*
// @match https://e-hentai.org/*
// @grant GM_xmlhttpRequest
// @grant GM_getResourceText
// @connect panda.chaika.moe
// @resource iziToast.min.css https://cdn.jsdelivr.net/npm/[email protected]/dist/css/iziToast.min.css
// @resource iziToast.min.js https://cdn.jsdelivr.net/npm/[email protected]/dist/js/iziToast.min.js
// ==/UserScript==

/*
  inject resource
*/
((...names) => {
  if (typeof GM_getResourceText === void 0) {
    const text = "need grant GM_getResourceText permission";
    alert(text);
    throw text;
  }
  for (const name of names) {
    const data = GM_getResourceText(name);
    if (!data.length) {
      console.warn(`resource ${name} have no content`);
    }
    if (name.endsWith(".js")) {
      const el = document.createElement("script");
      el.textContent = data;
      document.body.appendChild(el);
    } else if (name.endsWith(".css")) {
      const el = document.createElement("style");
      el.textContent = data;
      document.body.appendChild(el);
    }
  }
})('iziToast.min.css', 'iziToast.min.js');




(function() {
  "use strict";
  const request = (url, { json = null, form = null } = {}) => {
    return new Promise((resolve, reject) => {
      const r = GM_xmlhttpRequest != null ? GM_xmlhttpRequest : XMLHttpRequest;
      let method = "POST";
      let ct, data;
      if (json) {
        ct = "application/json";
        data = JSON.stringify(json);
      } else if (form) {
        ct = "application/x-www-form-urlencoded";
        data = new FormData();
        for (const [k, v] of Object.entries(form)) {
          data.append(k, v);
        }
      } else {
        method = "GET";
      }
      r({
        url,
        data,
        method,
        headers: {
          "Content-Type": ct
        },
        onload: (resp) => {
          resolve(resp.responseText);
        },
        onerror: (err) => {
          reject(err);
        }
      });
    });
  };
  const main = async () => {
    const u = new URL(location.href);
    const kw = u.searchParams.get("f_search");
    if (!kw) {
      return;
    }
    let content;
    try {
      content = await request(`https://panda.chaika.moe/archive-autocomplete/?q=${kw}`);
    } catch (error) {
      alert("can not connect to panda.chaika.moe. see more info from dev tool");
      throw error;
    }
    if (content === noMatchesFound) {
      console.log("nothing found in panda");
      return;
    }
    const openPanda = () => {
      window.open(`https://panda.chaika.moe/search/?title=${kw}`);
    };
    iziToast.show({
      message: "Find a panda",
      messageColor: "#ffffff",
      color: "#363940",
      timeout: 1e4,
      position: "topRight",
      onOpened: (_, el) => {
        el.addEventListener("click", openPanda);
      },
      onClosed(_, el) {
        el.removeEventListener("click", openPanda);
      }
    });
  };
  const noMatchesFound = '<span class="block"><em>No matches found</em></span>';
  main();
})();