微件:Extract collapsed navbox list:修订间差异
跳转到导航
跳转到搜索
删除的内容 添加的内容
小无编辑摘要 |
小无编辑摘要 |
||
(未显示同一用户的2个中间版本) | |||
第1行: | 第1行: | ||
<script> |
<script> |
||
// Get target elements. |
|||
const elements = document.getElementsByClassName('collapsed-navbox-list-base'); |
const elements = document.getElementsByClassName('collapsed-navbox-list-base'); |
||
const lists = document.getElementsByClassName('collapsed-navbox-list'); |
const lists = document.getElementsByClassName('collapsed-navbox-list'); |
||
const extracters = document.getElementsByClassName('collapsed-navbox-list-extracter'); |
const extracters = document.getElementsByClassName('collapsed-navbox-list-extracter'); |
||
const unprocessed = document.getElementsByClassName('unprocessed-collapsed-navbox-list'); |
|||
// Will not be processed when 'Collapsed navbox list' does not present on the page. |
|||
if (elements.length !== 0) { |
if (elements.length !== 0) { |
||
function extract(element, index, array) { |
function extract(element, index, array) { |
||
// Use computed style to reading common css. |
|||
let styles = getComputedStyle(element); |
let styles = getComputedStyle(element); |
||
// Move the details into 'collapsed-navbox-list-base'. |
|||
if (styles.display !== 'hidden' && styles.display !== 'none' ) { |
if (styles.display !== 'hidden' && styles.display !== 'none' ) { |
||
const list = lists[index]; |
const list = lists[index]; |
||
第14行: | 第17行: | ||
list.appendChild(cloned); |
list.appendChild(cloned); |
||
extracter.remove(); |
extracter.remove(); |
||
// Parent node of 'collapsed-navbox-list-base' should be 'unprocessed-collapsed-navbox-list'. |
|||
element.parentNode.removeAttribute('class'); |
|||
const clonedCollapsed = unprocessedCollapsed.cloneNode(true); |
|||
clonedCollapsed.classList.remove('unprocessed-collapsed-navbox-list') |
|||
unprocessedCollapsed.parentNode.appendChild(clonedCollapsed); |
|||
unprocessedCollapsed.parentNode.removeChild(unprocessedCollapsed); |
|||
} else { |
} else { |
||
// Remove the 'collapsed-navbox-list-base' because the details will display on extacter. |
|||
element.remove(); |
element.remove(); |
||
} |
} |
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>