微件:Extract collapsed navbox list

来自Hyacinth
草awa留言 | 贡献2024年4月18日 (四) 18:22的版本
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转到导航 跳转到搜索
<script>
// Get target elements.
const elements = document.getElementsByClassName('collapsed-navbox-list-base');
const lists = document.getElementsByClassName('collapsed-navbox-list');
const extracters = document.getElementsByClassName('collapsed-navbox-list-extracter');

// Will not be processed when 'Collapsed navbox list' does not present on the page.
if (elements.length !== 0) {
    function extract(element, index, array) {
        // Use computed style to reading common css.
    	let styles = getComputedStyle(element);
    	// Move the details into 'collapsed-navbox-list-base'.
        if (styles.display !== 'hidden' && styles.display !== 'none' ) {
            const list = lists[index];
            const extracter = extracters[index];
            const cloned = extracter.cloneNode(true);
            list.appendChild(cloned);
            extracter.remove();
            // Parent node of 'collapsed-navbox-list-base' should be 'unprocessed-collapsed-navbox-list'.
            element.parentNode.removeAttribute('class');
        } else {
            // Remove the 'collapsed-navbox-list-base' because the details will display on extacter.
        	element.remove();
        }
    }
    
	Array.from(elements).forEach(extract);
}
</script>