微件:Extract collapsed navbox list:修订间差异

删除的内容 添加的内容
草awa留言 | 贡献
Cao awa将页面Widget:Extract collapsed navbox list的内容模型从“wikitext”更改为“JavaScript”
草awa留言 | 贡献
无编辑摘要
 
(未显示同一用户的11个中间版本)
第1行:
<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) {
for (let i = 0; i < elements.length; i++) {
// Use computed style to reading common css.
const element = elements[i];
let styles = getComputedStyle(element);
if (element.style.display == 'hidden' || element.style.display == 'none' ) {
// Move the details into const 'collapsed-navbox-list = lists[i];-base'.
if (element.stylestyles.display !== 'hidden' ||&& element.stylestyles.display !== 'none' ) {
const cloned = list.cloneNode(true);
const extracterlist = extracterslists[iindex];
const extracter.appendChild(cloned) = extracters[index];
elementconst cloned = extracter.removecloneNode(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>