一个小建议:能否在打开页面的同时,自动展开该页面的子页面 - 链滴
基于以上帖子及下面的“中键展开文档树”的代码,哪位大佬能帮忙写一个 js 代码,实现以下功能:
如果当前文档下面含有子文档:
- 鼠标左键文档树条目,展开文档树(显示该文档下的子文档),不打开文档
- 鼠标中键文档树条目,不展开文档树,打开文档(原左键的默认功能)
先感谢 @zxkmm,@Undii,@wilsons 等大佬的相关插件、代码和热心帮助!
// 中键展开文档树:基于https://ld246.com/article/1682476267736 (function(){ let g_reset = setInterval(main, 2000); function main() { if (document.querySelector('.sy__file')) { clearInterval(g_reset); }else{ return false; } document.querySelector('.sy__file').addEventListener('mousedown', event => { if (event.button != 1) return; let notTitleFlag = false; if (!event.target.classList.contains('b3-list-item__text')) notTitleFlag = true; let target = event.target.parentNode; let temp = event.target; //console.log("0426",event); for (let i = 0; i < 4 && temp; i++) { if (temp?.getAttribute("data-type") == "navigation-file" || temp?.getAttribute("data-type") == "navigation-root") { target = temp; break; } temp = temp?.parentNode; } //console.log("0426target", target); if (target?.getAttribute("data-type") == "navigation-file" || target?.getAttribute("data-type") == "navigation-root") { const b3ListItemToggle = target.querySelector('.b3-list-item__toggle'); const title = target.querySelector('.b3-list-item__text'); if (b3ListItemToggle.classList.contains('fn__hidden')) return; event.preventDefault(); b3ListItemToggle.click(); if (event.ctrlKey) { title.click(); } } }, true); } })();