()
| 1594 | |
| 1595 | // 屏蔽热榜杂项 |
| 1596 | function blockHotOther() { |
| 1597 | if (!menu_value('menu_blockTypeLiveHot')) return; |
| 1598 | |
| 1599 | const isQuestionItem = (hotItem) => { |
| 1600 | const linkItem = hotItem.querySelector('.HotItem-content a'); |
| 1601 | if (linkItem === null) return false; |
| 1602 | return /\/question\/\d+/.test(linkItem.href); |
| 1603 | } |
| 1604 | |
| 1605 | const block = () => { |
| 1606 | removeLiveItems(); |
| 1607 | fixItemRank(); |
| 1608 | }; |
| 1609 | |
| 1610 | // 移除非问题的内容 |
| 1611 | const removeLiveItems = () => { |
| 1612 | const hotItems = document.querySelectorAll('.HotList-list .HotItem'); |
| 1613 | for (const item of hotItems) { |
| 1614 | if (!isQuestionItem(item)) item.remove(); |
| 1615 | } |
| 1616 | } |
| 1617 | |
| 1618 | // 修复排行榜序号 |
| 1619 | const fixItemRank = () => { |
| 1620 | const hotItems = document.querySelectorAll('.HotList-list .HotItem:not([hidden])'); |
| 1621 | hotItems.forEach((item, index) => { |
| 1622 | const rank = item.querySelector('.HotItem-index .HotItem-rank'); |
| 1623 | if (rank !== null) rank.innerText = index + 1; |
| 1624 | }); |
| 1625 | } |
| 1626 | |
| 1627 | const blockLive_content = (mutationsList, observer) => { |
| 1628 | for (const mutation of mutationsList) { |
| 1629 | for (const target of mutation.addedNodes) { |
| 1630 | if (target.classList.contains('.HotItem')) { |
| 1631 | block(); |
| 1632 | } |
| 1633 | } |
| 1634 | } |
| 1635 | } |
| 1636 | |
| 1637 | const observer = new MutationObserver(blockLive_content); |
| 1638 | observer.observe(document, { childList: true, subtree: true }); |
| 1639 | |
| 1640 | // 初始移除 |
| 1641 | block(); |
| 1642 | } |
| 1643 | |
| 1644 | // 将关注/推荐/热榜/专栏的选项去掉默认的点击事件改成静态链接(针对首页互相切换(知乎这里切换是动态加载的),为了避免功能交叉混乱 |
| 1645 | // 针对所有页面 |
no test coverage detected