notion auto expend

display to the current (nested) page in the sidebar

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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); // 每秒检测一次,可以根据需要调整间隔时间
})();