Bangumi Staff Folding

Fold the excessive long staff list

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Bangumi Staff Folding
// @namespace    https://greasyfork.org/users/193469
// @description  Fold the excessive long staff list
// @version      1.2
// @author       Rui LIU (@liurui39660)
// @match        https://bgm.tv/subject/*
// @match        https://bangumi.tv/subject/*
// @icon         https://icons.duckduckgo.com/ip2/bgm.tv.ico
// @license      MIT
// @run-at       document-end
// ==/UserScript==

(function () {
	'use strict';

	// If there are 12 names, the 11th and 12th will be hidden
	// Another typical value is 1, where only the most essential info is shown
	const threshold = 10;

	for (const li of document.querySelectorAll('#infobox > li')) {
		if (li.childNodes.length > threshold * 2 + 1) { // Entry name and commas
			const folded = document.createElement('span');
			for (let i = threshold * 2 + 1; i < li.childNodes.length;)
				folded.append(li.removeChild(li.childNodes[i]));
			folded.hidden = true;
			li.append(folded);

			const button = document.createElement('a');
			button.text = `\t[+${Math.ceil(folded.childNodes.length / 2)}]`;
			button.alt_text = '\t[<<<]';
			button.href = 'javascript:;';
			button.onclick = () => {
				folded.hidden = !folded.hidden;
				[button.text, button.alt_text] = [button.alt_text, button.text];
			};
			li.append(button);
		}
	}
})();