Greasy Fork

Greasy Fork is available in English.

Show Artist Pixiv ID

Show Pixiv ID of the artist under nickname in the illustration page

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Show Artist Pixiv ID
// @namespace   http://greasyfork.icu/en/users/37676
// @description Show Pixiv ID of the artist under nickname in the illustration page
// @match       *://*.pixiv.net/*/artworks/*
// @run-at      document-end
// @version     1.0.9
// @grant       none
// @license     Creative Commons Attribution 4.0 International Public License; http://creativecommons.org/licenses/by/4.0/
// ==/UserScript==

let pageObserver = null;
const nextData = document.querySelector('#__NEXT_DATA__');

if (nextData && !pageObserver) {
    try {
        const nextJson = JSON.parse(nextData.text);
        const illustID = nextJson?.query?.id;

        if (illustID) {
			fetch('https://www.pixiv.net/ajax/illust/' + illustID)
				.then(function(response) { return response.json(); })
				.then(function(json) {
					const userID = json?.body?.userId;
					const userName = json?.body?.userName;
					const userAccount = json?.body?.userAccount;
					
					if (userID && userName && userAccount) {
						if (!pageObserver) {
							pageObserver = new MutationObserver(function(mutations) {
								const profileElement = document.querySelectorAll('a[href*="/users/'+userID+'"]');

								if (profileElement.length > 0) {
									for (let i=0; i < profileElement.length; i++) {
										const imageElement = profileElement[i].querySelectorAll('div[role*="img"]');

										if (imageElement.length > 0) {
											for (let j=0; j < imageElement.length; j++) {
												const parentElement = imageElement[j].parentElement;

												if (parentElement) {
													const nextElement = parentElement.nextElementSibling;

													if (nextElement) {
														if (nextElement.innerHTML.indexOf(userAccount) < 0) {
															if (parentElement.innerHTML.indexOf(userName) < 0) {
																nextElement.innerHTML += '<div>'+userName+'</div>';
															}
															
															nextElement.innerHTML += '<div>'+userAccount+'</div>';
														}
													}
												}
											}
										}
									}
								}
							});

							pageObserver.observe(document.querySelector('#__next'), {
								childList: true,
								subtree: true
							});
						}
					}
            });
        }

    } catch(e) {

    }
}