Bangumi Staff Folding

Fold the excessive long staff list

As of 22.09.2021. See апошняя версія.

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 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         Bangumi Staff Folding
// @namespace    https://greasyfork.org/users/193469
// @description  Fold the excessive long staff list
// @version      1.1
// @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 = '';
			button.onclick = ev => {
				ev.preventDefault();
				folded.hidden = !folded.hidden;
				[button.text, button.alt_text] = [button.alt_text, button.text];
			};
			li.append(button);
		}
	}
})();