Greasy Fork

Greasy Fork is available in English.

Pixiv显示百科按钮

显示一个打开Pixiv百科页面的按钮

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name              Pixiv显示百科按钮
// @description       显示一个打开Pixiv百科页面的按钮
// @namespace         moe.cangku.mengzonefire
// @version           1.0.4
// @author            mengzonefire
// @license           MIT
// @contributionURL   https://afdian.net/@mengzonefire
// @match             *://www.pixiv.net/*
// @require           https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js
// @run-at            document-start
// ==/UserScript==
!(() => {
  "use strict";
  const htmlTag = "div.sc-1973m3p-0";
  var tag = "";
  function addBtn() {
    let html_tag = $(htmlTag);
    if (html_tag.length) {
      let className = html_tag[0].children[0].className;
      let htmlBtn = `<button id="mzf_dic_btn" aria-disabled="false" class="${className}" onclick="window.open('https://dic.pixiv.net/a/${tag}','_self')">Pixiv百科全书</button>`;
      html_tag.before(htmlBtn);
    } else setTimeout(addBtn, 100);
  }
  function start() {
    let MutationObserver =
      window.MutationObserver ||
      window.WebKitMutationObserver ||
      window.MozMutationObserver;
    let observer = new MutationObserver(urlChangeHandler);
    observer.observe($("head > title")[0], {
      childList: true,
    });
  }
  function urlChangeHandler() {
    tag = window.location.href.match(/\/tags\/([^/]+)/);
    if (tag) {
      tag = tag[1];
      console.log(`match tag: ${decodeURIComponent(tag)}`);
      addBtn();
    }
  }
  jQuery(start);
})();