微件:External demands:修订间差异

来自Hyacinth
跳转到导航 跳转到搜索
删除的内容 添加的内容
草awa留言 | 贡献
无编辑摘要
草awa留言 | 贡献
Remove redundant console print.
 
(未显示同一用户的18个中间版本)
第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.style.display = 'none';
externalDemandShell.remove();
} else {
} else {
const appendTo = document.getElementById('external_demand');
const appendTo = document.getElementById('external_demand');


const cats = new Map();
const cats = new Map();

function makeMap(element, index, array) {
for (let i = 0; i < elements.length; i++) {
const element = elements[i];
const clone = element.cloneNode(true);
const clone = element.cloneNode(true);
element.parentNode.removeChild(element);
console.log(clone.title);
if (!cats.has(clone.title)) {
if (!cats.has(clone.title)) {
cats.set(clone.title,new Array());
cats.set(clone.title,new Array());
第19行: 第18行:
cats.get(clone.title).push(clone);
cats.get(clone.title).push(clone);
clone.style.display = 'inline';
clone.style.display = 'inline';
clone.classList.remove('external_demand_span')
clone.classList.remove('external_demand_span');
}
}
Array.from(elements).forEach(makeMap);


function handler(value, key, map) {
function handler(value, key, map) {
第27行: 第28行:
appendTo.appendChild(p);
appendTo.appendChild(p);
const duplicates = new Map();
const duplicates = new Map();
const liShell = new Map();
const displayed = new Map();
const ul = document.createElement('ul');
const ul = document.createElement('ul');
value.forEach((s) => {
value.forEach((s) => {
const externalTarget = s.lastChild.title;
const externalTargetData = s.lastChild;
const externalTarget = externalTargetData.title;
const displayName = externalTargetData.lastChild.title;
if (duplicates.has(externalTarget)) {
if (duplicates.has(externalTarget)) {
console.log(duplicates.get(externalTarget))
const displayNames = displayed.get(externalTarget);
if (displayNames != null && displayNames.indexOf(displayName) == -1) {
console.log(duplicates.get(externalTarget).lastChild)
const duplicatedUl = document.createElement('ul');
if (duplicates.get(externalTarget).lastChild.className == 'external_demand_duplicate') {
const duplicatedUl = document.createElement('ul');
const duplicatedLi = document.createElement('li');
const duplicatedLi = document.createElement('li');
const duplicatedAlias = s.lastChild.cloneNode(true);
const duplicatedAlias = duplicates.get(externalTarget).lastChild.cloneNode(true);
duplicatedAlias.style.display = 'inline';
duplicatedLi.appendChild(duplicatedAlias);
duplicatedLi.appendChild(duplicatedAlias);
duplicatedUl.appendChild(duplicatedLi);
duplicatedUl.appendChild(duplicatedLi);
liShell.get(externalTarget).appendChild(duplicatedUl);
duplicates.get(externalTarget).appendChild(duplicatedUl);
displayed.get(externalTarget).push(displayName);
}
}
} else {
} else {
const li = document.createElement('li');
const li = document.createElement('li');
duplicates.set(externalTarget, s);
duplicates.set(externalTarget, li);
liShell.set(externalTarget, li);
displayed.set(externalTarget, [displayName]);
li.appendChild(s);
li.appendChild(s);
ul.appendChild(li);
ul.appendChild(li);

2024年9月25日 (三) 03:29的最新版本

<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();
	
	function makeMap(element, index, array) {
	    const clone = element.cloneNode(true);
	    element.parentNode.removeChild(element);
	    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');
	}
	
	Array.from(elements).forEach(makeMap);

	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>