notion auto expend

display to the current (nested) page in the sidebar

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

You will need to install an extension such as Tampermonkey to install this script.

Tendrás que instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Tendrás que instalar una extensión como Tampermonkey antes de poder instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         notion auto expend
// @namespace    http://tampermonkey.net/
// @version      2023-12-24
// @author       You
// @match        https://www.notion.so/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=notion.so
// @require     https://code.jquery.com/jquery-3.7.1.min.js
// @description  display  to the current (nested) page in the sidebar
// @license MIT
// @grant        none
// ==/UserScript==

(function () {
  'use strict';

  // Your code here...
  let currentPagePath = "";

  // 检测路径变化
  const checkPathChange = () => {
    const allpathstr = $("div.shadow-cursor-breadcrumb").text()
    if (allpathstr !== currentPagePath) {
      // 执行路径变化后的操作
      console.log('Path has changed!', currentPagePath, "=>", allpathstr);
      // 这里可以添加你想要执行的代码

      // 更新当前页面路径
      currentPagePath = allpathstr;
      const allpath = allpathstr.split("/")
      const s = ".notion-outliner-private:nth-child(1) > div "
      const level1p = ".notion-outliner-private:nth-child(1) > div > .notion-selectable > a > div"
      let levelP = ""
      for (let i = 1; i < allpath.length; i++) {
        const path = allpath[i - 1]
        console.log(i, path)
        if (i === 1) {
          const level1 = $(level1p)
          //
          for (let j = 1; j <= level1.length; j++) {
            let rootitem = level1[j - 1]
            if (rootitem.innerText === path) {
              console.log("find!", path)
              const buttonpath = s + `> .notion-selectable:nth-child(${j})` + `> a > div > div:nth-child(1)>div`
              levelP = s + `> .notion-selectable:nth-child(${j})`
              // 判断attr
              const b = $(buttonpath)
              const attr = b.attr("aria-expanded")
              console.log("attr", attr)
              if (attr === "false") {
                console.log("click")
                b.click()
              }
            }
          }
          // console.log("xxxx",level1[0].innerText)
        } else {
          const level = $(levelP + ">div > div> " + ".notion-selectable" + ">a >div")
          console.log(levelP)
          for (let j = 1; j <= level.length; j++) {
            let rootitem = level[j - 1]
            if (rootitem.innerText === path) {
              console.log("find 2!", path, j)
              const buttonpath = levelP + `>div > div> .notion-selectable:nth-child(${j})` + ">a >div" + "> div:nth-child(1)>div"
              levelP = levelP + `>div > div> .notion-selectable:nth-child(${j})`
              // 判断attr
              console.log("path is ", buttonpath)
              const b = $(buttonpath)
              const attr = b.attr("aria-expanded")
              console.log("attr", i, attr)
              if (attr === "false") {
                console.log("click")
                b.click()
              }
            }
          }
        }
      }
    }
    setTimeout(checkPathChange, 1000);
  };

  // 定时检测路径变化
  setTimeout(checkPathChange, 1000); // 每秒检测一次,可以根据需要调整间隔时间
})();