前言
链滴上很多人需要,我也需要,似乎有相关插件,秉承着能自己干就不靠插件的原则,自己写代码了,用时 12 分钟写完,需要自取,具体看效果图!
多级目录,只需要单击就能展开子目录,不会打开父级文档(直接把父级文档当成“目录了”)。
如果你真的很想打开父级文档,你可以这样做。
JS 代码片段
自行添加 JS 代码片段,刷新页面即可。
const filetreeObserver = new MutationObserver(mutations => { mutations.forEach(mutation => { if ((mutation.type === "childList" && mutation.addedNodes.length > 0) || mutation.type === "characterData") { let addedNode = mutation.addedNodes[0]; try { if(addedNode.nodeName === "UL" && addedNode.offsetParent.className.includes("layout-tab-container")) { addedNode.childNodes.forEach((childNode) => { childNode.addEventListener("click", function (event) { if(childNode.querySelector(".b3-list-item__toggle:not(.fn__hidden)")) { if((event.target.className && event.target.className.baseVal === "") || (event.target.className.baseVal && event.target.className.baseVal.includes("b3-list-item__arrow")) || event.target.className && event.target.className.includes("b3-list-item__toggle")) { return; } childNode.dataset.type = "navigation-parent"; childNode.querySelector(".b3-list-item__toggle").click(); setTimeout(() => { childNode.dataset.type = "navigation-file"; }, 50) } }) }) } } catch (error) {} // console.log(mutation.addedNodes) } }); }); filetreeObserver.observe(document.body, { attributes: true, characterData: true, childList: true, subtree: true });
乍一看代码块写的好臭,实际上不少坑要补,随便写成这样,反正我自己没试出什么 bug 来,应该是完美的,有问题可以反馈一起讨论,拿走使用了的求回复一下 😂
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于