Skip to content

Commit

Permalink
feat✨: 新增油猴脚本react中文目录补全;
Browse files Browse the repository at this point in the history
  • Loading branch information
simply-none committed Nov 11, 2022
1 parent 1254320 commit 0983525
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 1 deletion.
107 changes: 107 additions & 0 deletions react中文文档目录补全.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// ==UserScript==
// @name react中文文档目录补全-dev
// @version 0.0.5
// @description 展示react中文文档右侧目录,支持2、3、4级目录
// @author jade qiu
// @match https://zh-hans.reactjs.org/docs/*
// @match https://react.docschina.org/docs/*
// @icon https://zh-hans.reactjs.org/favicon.ico
// @grant GM_addStyle
// @require https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.3/moment.min.js
// @license MIT
// @namespace https://greasyfork.org/users/909394
// ==/UserScript==

;(function () {
'use strict'

const style = `
.custom-ul {
padding: 10px 0 10px 20px;
font-size: 10px;
background: #dadada;
}
.custom-li {
font-family: source-code-pro,Menlo,Monaco,Consolas,Courier New,monospace;
font-size: 14px;
font-weight: 100;
min-width: 36em;
padding-top: 3px;
}
.custom-li-h3 {
padding-left: 20px;
}
.custom-li-h4 {
padding-left: 20px;
}
.custom-li:hover {
backgound-color: #61dafb;
}
.custom-li:first-child {
padding-top: 0;
}
`

GM_addStyle(style)

let timer = null

const render = function () {
let a = 0
timer = setInterval(() => {
a++
if (a === 5) {
clearInterval(timer)
return false
}
const currentPageTitle = document.querySelector('article header h1')
const allPageTitle = Array.from(document.querySelectorAll('ul[id^="section_"] a'))
const currentPageSecondLevelTitle = Array.from(
document.querySelectorAll('article>div>div>h2,article>div>div>h3,article>div>div>h4')
)
allPageTitle.map((page) => {
const pageInnerText = page.innerText.replace(/^[0-9]\.\s/, '')
let run = undefined
if (pageInnerText === 'React' && currentPageTitle.innerText === 'React 顶层 API') {
run = true
} else if (pageInnerText === currentPageTitle.innerText) {
run = true
}
if (run) {
const ul = document.createElement('ul')
ul.classList.add('custom-ul')
currentPageSecondLevelTitle.map((second) => {
const co = second.cloneNode(true)
co.classList.add('custom-li', 'custom-li-' + co.nodeName.toLowerCase())
ul.appendChild(co)
})
if (page.parentNode.children.length >= 2) {
page.parentNode.removeChild(page.parentNode.childNodes[1])
}
page.parentNode.appendChild(ul)
}
})
}, 1000)
}

// 监听浏览器的返回上一页事件
window.addEventListener('popstate', function () {
clearInterval(timer)
render()
})

window.addEventListener('load', function () {
clearInterval(timer)
render()
})

window.addEventListener('click', (e, a) => {
const isA = e.path.find((path) => path.nodeName === 'A')
if (!isA) {
return true
}
clearInterval(timer)
render()
})
})()
3 changes: 2 additions & 1 deletion usage-frame/react/react.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# react 基础知识
# react 基础知识

7 changes: 7 additions & 0 deletions usage-project/项目启动报错汇总-react.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# react项目启动报错汇总

## 报错1:You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.1).

场景:运行命令`npx create-react-app my-app`创建react应用时出现该错误

解决方法:根据命令行提示删除全局包`npm uninstall -g create-react-app`无效,[网上查找内容](https://blog.csdn.net/tuzi007a/article/details/123333059),找到了解决思路,即重新安装该包,然后再运行命令创建react应用

0 comments on commit 0983525

Please sign in to comment.