-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1254320
commit 0983525
Showing
3 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
# react 基础知识 | ||
# react 基础知识 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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应用 |