find panda

check panda.chaika.moe for related galleries when searching

اعتبارا من 02-12-2022. شاهد أحدث إصدار.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==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();
})();