微件:SaltVoteContainer:修订间差异

添加1,600字节 、​ 2024年3月18日 (星期一)
编辑“微件:SaltVoteContainer” // 维基盐编辑器
(一些问题修复 // 维基盐编辑器)
(编辑“微件:SaltVoteContainer” // 维基盐编辑器)
/** 主流程 */
/** @type {(el: HTMLDivElement) => void} */
const mainprocess = (el) => {
el.classList.remove("not-init");
console.log(el);
const barEl = el.querySelector(".salt-vote-bar");
const colorEl = el.querySelector(".salt-vote-color");
const list = el.querySelector("ul.salt-vote-options");
const lists = list && list.querySelectorAll("li");
const descUl = el.querySelector(".salt-vote-describe");
/** 收集的投票信息 @type {{name: string, set: string[]}[]} */
const descLi = descUl && descUl.querySelectorAll("li");
/** 收集的投票信息 @type {{name: string, set: string[], li: HTMLElement, desc?: HTMLElement}[]} */
const collect = [];
/** 收集的投票信息 @type {{name: string, setdesc: string[]HTMLElement}[]} */
const descCollect = [];
/** 有问题的投票信息 @type {Record<string, Set<string>>} */
const wrongCollect = {};
else color.push(...defaultColor);
}
// 获取投票选项描述
const descList = Array.from(descLi || []);
descList.forEach((desc) => {
const option = desc.querySelector(".salt-vote-desc-option");
const value = desc.querySelector(".salt-vote-desc");
if (!option || !value) return;
const title v= option.textContent =|| res"";
const thisCollect = { name: title, desc: value };
descCollect.push(thisCollect);
desc.style.setProperty("--height", "0");
});
// 获取投票信息
const liList = Array.from(lists);
liList.forEach((li, liIndex) => {
// salt-vote-option salt-vote-voter
const option = li.querySelector(".salt-vote-option");
/** @type {HTMLElement | null} */
const voter = li.querySelector(".salt-vote-voter");
if (!option || !voter) return;
const voters = Array.from(voter.querySelectorAll("a"));
// if (title in collect) return;
const thisCollect = { name: title, set: [], li: li };
voters.forEach((v) => {
const res = v.title
.replace(/^(?:User|U|用户):/i, "")
.replace(/\s/g, "_");
if (thisCollect.set.includes(res)) {
v.remove();
}
thisCollect.set.push(res);
// 允许自定义用户名样式
v.textContent = res;
if (
!v.textContent ||
v.textContent.toUpperCase().trim().replace(/\s/g, "_") !==
res.toUpperCase()
)
v.textContent = res;
});
collect.push(thisCollect);
// 配色
li.style.setProperty("--vote-color", at(color, liIndex));
// 点击展开选项描述
const desc = descCollect.find(({ name }) => name === title);
if (desc) {
const descEl = desc.desc;
thisCollect.desc = descEl;
li.classList.add("has-desc");
descEl.classList.add("salt-vote-option-hooked");
descEl.style.setProperty("--height", `${descEl.scrollHeight}px`);
descEl.style.setProperty("--vote-color", at(color, liIndex));
li.addEventListener("click", () => {
if (descEl.classList.contains("show")) {
descEl.classList.remove("show");
} else {
descEl.classList.add("show");
descEl.style.setProperty("--height", `${descEl.scrollHeight}px`);
}
});
li.appendChild(descEl);
}
});
// 绘制图形
barEl.innerHTML = renderBar(collect, color);
}
console.log(collect, renderBar(collect, color));
el.classList.remove("not-init");
};
 
const main = () => getAllNotInitContainer().forEach((el) => process(el));
 
setTimeout(() => {
getAllNotInitContainer().forEach((el) => main(el));
}, 0);
setTimeout(() => {
main();
}, 66);
setInterval(() => {
getAllNotInitContainer().forEach((el) => main(el));
}, 1000500);
})(window);
</script></includeonly>