// ==UserScript==
// @name notion plugin
// @namespace http://tampermonkey.net/
// @version 0.5
// @description add notion outline view
// @author fengxxc
// @match https://www.notion.so/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=notion.so
// @grant none
// @license MIT
// @downloadURL https://update.greasyfork.icu/scripts/445715/notion%20plugin.user.js
// @updateURL https://update.greasyfork.icu/scripts/445715/notion%20plugin.meta.js
// ==/UserScript==
(function() {
'use strict';
/**
* 一、二、三 级标题的className分别为
* notion-header-block
* notion-sub_header-block
* notion-sub_sub_header-block
*/
function getOutlineTokens() {
const headerBlock = document.querySelectorAll('.notion-header-block,.notion-sub_header-block,.notion-sub_sub_header-block')
const tokens = []
for (var i = 0; i < headerBlock.length; i++) {
const id = headerBlock[i].getAttribute('data-block-id').replaceAll('-', '')
// const notranslate = headerBlock[i].querySelector('.notranslate')
const level = headerBlock[i].className.split('sub').length
const header = headerBlock[i].innerText
tokens.push({id, level, header})
}
return tokens
}
function getOutlineHTMLs(outlineTokens) {
const pathname = window.location.pathname
return outlineTokens.map(token => (`