(
function
() {
"use strict"
;
const tableSelector = `div
#threadlist table`;
const appendSelector = `ul
#thread_types`;
const allHideTypes = [
"hide-by-solved"
,
"hide-by-reply"
,
"hide-by-lt-cb"
];
const btnList = [];
const filterBtnType = 1;
function
createBtn(text, color) {
const btn = document.createElement(
"li"
);
btn.innerHTML = `<a style=
"background-color:${color};border-radius:5px;color:#fff;cursor:pointer;"
>${text}</a>`;
btnList.push(btn);
return
btn;
}
function
recoverByType(type) {
const lines = [...document.querySelectorAll(`${tableSelector}>tbody[id*=normalthread_][${type}]`)];
lines.forEach((i) => {
i.setAttribute(type,
false
);
if
(allHideTypes.every((t) => !i.getAttribute(t) || i.getAttribute(t) ==
"false"
)) {
i.style.display =
""
;
}
});
}
function
showBtnTop(btnList) {
btnList.forEach((i) => document.querySelector(appendSelector).appendChild(i));
}
function
showBtnFloat(btnList) {
const domHead = document.getElementsByTagName(
'head'
)[0];
const domStyle = document.createElement(
'style'
);
domStyle.type =
'text/css'
;
domStyle.rel =
'stylesheet'
;
const filterStyle = `
#filterBox {
position: fixed;
top: 50%;
transform: translateY(-50%);
right: 20px;
gap: 20px;
flex-direction: column;
z-index: 99999;
display: flex;
}
#filterBox>li {
margin-top: 5px;
}
#filterBox>li>a {
padding: 10px;
border-color: rgb(0,102,255);
border-radius: 5px;
background-color: white;
color: rgb(0,102,255);
margin-right: 10px;
box-shadow: rgb(207,207,207) 1px 1px 9px 3px;
text-decoration: none;
}
`;
domStyle.appendChild(document.createTextNode(filterStyle));
domHead.appendChild(domStyle);
const filterButtonBox = document.createElement(
"ul"
);
filterButtonBox.id =
"filterBox"
;
btnList.forEach((i) => {
filterButtonBox.appendChild(i);
});
document.body.appendChild(filterButtonBox);
}
window.addEventListener(
"load"
, () => {
{
const filterNonSolvedBtn = createBtn(
"移除已解决"
,
"#66ccff"
);
filterNonSolvedBtn.addEventListener(
"click"
, () => {
const lines = [...document.querySelectorAll(`${tableSelector}>tbody[id*=normalthread_]`)];
lines.forEach((i) => {
if
(!(i.innerText ||
""
).includes(
"已解决"
))
return
;
i.setAttribute(
"hide-by-solved"
,
true
);
i.style.display =
"none"
;
});
});
}
{
const showNonSolvedBtn = createBtn(
"还原已解决"
,
"Green"
);
showNonSolvedBtn.addEventListener(
"click"
, () => recoverByType(
"hide-by-solved"
));
}
{
const filterByReply = createBtn(`移除回复多于 <input style=
"width:2em;height:1em;pointer-events:all;text-align:center"
/>`,
"#66ccff"
);
const replyCount = filterByReply.querySelector(
"input"
);
replyCount.addEventListener(
"click"
, (e) => e.stopPropagation());
replyCount.value = 0;
filterByReply.addEventListener(
"click"
, () => {
const maxCount = replyCount.value;
const lines = [...document.querySelectorAll(`${tableSelector}>tbody[id*=normalthread_]`)];
lines.forEach((i) => {
const countEl = i.querySelector(
"tr>td.num>.xi2"
);
if
(parseInt(countEl.innerText) <= maxCount)
return
;
i.setAttribute(
"hide-by-reply"
,
true
);
i.style.display =
"none"
;
});
});
}
{
const showByReply = createBtn(
"还原回复多于x"
,
"Green"
);
showByReply.addEventListener(
"click"
, () => recoverByType(
"hide-by-reply"
));
}
{
const filterByCB = createBtn(`移除CB少于 <input style=
"width:2em;height:1em;pointer-events:all;text-align:center"
/>`,
"#66ccff"
);
const CBCount = filterByCB.querySelector(
"input"
);
CBCount.addEventListener(
"click"
, (e) => e.stopPropagation());
CBCount.value = 0;
filterByCB.addEventListener(
"click"
, () => {
const minCount = CBCount.value;
const lines = [...document.querySelectorAll(`${tableSelector}>tbody[id*=normalthread_]`)];
lines.forEach((i) => {
const cb = parseInt(i.innerText.replaceAll(
"\n"
,
""
).replace(/.*悬赏\s*(\d+)\s*CB\s*吾爱币.*/,
"$1"
));
if
(cb >= minCount)
return
;
i.setAttribute(
"hide-by-lt-cb"
,
true
);
i.style.display =
"none"
;
});
});
}
{
const showByReply = createBtn(
"还原CB少于x"
,
"Green"
);
showByReply.addEventListener(
"click"
, () => recoverByType(
"hide-by-lt-cb"
));
}
if
(filterBtnType === 1) {
showBtnTop(btnList);
}
else
if
(filterBtnType === 2) {
showBtnFloat(btnList);
}
});
})();