微件:External demands:修订间差异
跳转到导航
跳转到搜索
删除的内容 添加的内容
小无编辑摘要 |
小无编辑摘要 |
||
第4行: | 第4行: | ||
if (elements.length == 0) { |
if (elements.length == 0) { |
||
const externalDemandShell = document.getElementById('external_demand_shell'); |
const externalDemandShell = document.getElementById('external_demand_shell'); |
||
externalDemandShell. |
externalDemandShell.remove(); |
||
} else { |
} else { |
||
const appendTo = document.getElementById('external_demand'); |
const appendTo = document.getElementById('external_demand'); |
||
第13行: | 第13行: | ||
const element = elements[i]; |
const element = elements[i]; |
||
const clone = element.cloneNode(true); |
const clone = element.cloneNode(true); |
||
⚫ | |||
if (!cats.has(clone.title)) { |
if (!cats.has(clone.title)) { |
||
cats.set(clone.title,new Array()); |
cats.set(clone.title,new Array()); |
||
第19行: | 第20行: | ||
clone.style.display = 'inline'; |
clone.style.display = 'inline'; |
||
clone.classList.remove('external_demand_span'); |
clone.classList.remove('external_demand_span'); |
||
⚫ | |||
} |
} |
||
2024年4月18日 (四) 16:43的版本
<script>
const elements = document.getElementsByClassName('external_demand_span');
if (elements.length == 0) {
const externalDemandShell = document.getElementById('external_demand_shell');
externalDemandShell.remove();
} else {
const appendTo = document.getElementById('external_demand');
const cats = new Map();
for (let i = 0; i < elements.length; i++) {
const element = elements[i];
const clone = element.cloneNode(true);
element.remove();
if (!cats.has(clone.title)) {
cats.set(clone.title,new Array());
}
cats.get(clone.title).push(clone);
clone.style.display = 'inline';
clone.classList.remove('external_demand_span');
}
function handler(value, key, map) {
const p = document.createElement('p');
p.innerText = '来自' + key + '的条目:';
appendTo.appendChild(p);
const duplicates = new Map();
const displayed = new Map();
const ul = document.createElement('ul');
value.forEach((s) => {
const externalTargetData = s.lastChild;
const externalTarget = externalTargetData.title;
const displayName = externalTargetData.lastChild.title;
if (duplicates.has(externalTarget)) {
const displayNames = displayed.get(externalTarget);
if (displayNames != null && displayNames.indexOf(displayName) == -1) {
const duplicatedUl = document.createElement('ul');
const duplicatedLi = document.createElement('li');
const duplicatedAlias = s.lastChild.cloneNode(true);
duplicatedAlias.style.display = 'inline';
duplicatedLi.appendChild(duplicatedAlias);
duplicatedUl.appendChild(duplicatedLi);
duplicates.get(externalTarget).appendChild(duplicatedUl);
displayed.get(externalTarget).push(displayName);
}
} else {
const li = document.createElement('li');
duplicates.set(externalTarget, li);
displayed.set(externalTarget, [displayName]);
li.appendChild(s);
ul.appendChild(li);
}
})
appendTo.appendChild(ul);
}
cats.forEach(handler);
}
</script>