language searcher - nhentai.net

2023/12/5 下午10:54:48

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.

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.

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

// ==UserScript==
// @name        language searcher - nhentai.net
// @namespace   Violentmonkey Scripts
// @match       https://nhentai.net/*
// @grant       none
// @version     1.1
// @author      retiym
// @license MIT
// @description 2023/12/5 下午10:54:48
// ==/UserScript==

const language = {
  "ch": "chinese",
  "en": "english",
  "jp": "japanese"
}

const title_row = document.getElementsByTagName('h1')[0];

const style = document.createElement("style");

style.innerHTML = `
  .searcher_btn {
    width: 40px;
    height: 40px;
    user-select: none;
    background-color: #595959;
    border-radius: 4px;
    font-size: 20px;
    line-height: 40px;
  }
`
document.head.appendChild(style)

const getSearchTarget = () => {
  const url = window.location.pathname.split('/').filter((item) => item);
  const [category, name] = url

  if (category == 'g') return

  Object.entries(language).map(([key, value]) => {
    const destination = `/search/?q=${category}%3A${name}+%26%26+language%3A${value}`
    const btn = document.createElement("a")
    btn.appendChild(document.createTextNode(key));
    btn.classList.add('searcher_btn');
    btn.classList.add("tag");
    btn.setAttribute("href", destination);

    title_row.appendChild(btn);
  })
}

getSearchTarget();