-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
134 lines (122 loc) · 3.52 KB
/
index.html
File metadata and controls
134 lines (122 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>rxfile-write demo</title>
<script src="https://cdn.jsdelivr.net/npm/rxcornor@0.0.8/dist/index.js" id="rxcornor"
link="https://github.com/cheere/rxfile-write" target="_blank" title="Github" className="a b"></script>
<!-- 用于加载 README.md -->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked@4.0.0/marked.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.3.1/build/styles/default.min.css">
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.3.1/build/highlight.min.js"></script>
</head>
<body>
<h1>rxfile-write</h1>
<p>node.js - file -> add / remove / read。</p>
<br>
<hr>
<div id='content'></div>
<!-- 加载 md -->
<script type="text/javascript">
var swithcEnZh = false
$(function () {
mdToHtml()
});
</script>
<script>
function mdToHtml() {
const lang = getBrowserLang()
let newLang = lang
if (swithcEnZh === true) {
if (lang === 'zh_CN') newLang = 'en_US'
if (lang === 'en_US') newLang = 'zh_CN'
}
let readmeName = 'README'
if (newLang === 'zh_CN') {
readmeName += '_CH'
}
readmeName += '.md'
const dateTime = parseInt(new Date().getTime() / 108000)
readmeName += '?' + dateTime
let res = null;
$.ajax({
url: readmeName,
dataType: 'text',
success: function (data) {
document.getElementById('content').innerHTML = marked.parse(data)
addColor()
}
});
}
</script>
<script>
const getBrowserLang = function () {
let browserLang = navigator.language
? navigator.language
: navigator.browserLanguage;
let defaultBrowserLang = "";
if (
browserLang.toLowerCase() === "us" ||
browserLang.toLowerCase() === "en" ||
browserLang.toLowerCase() === "en_us"
) {
defaultBrowserLang = "en_US";
} else {
defaultBrowserLang = "zh_CN";
}
return defaultBrowserLang;
}
</script>
<script>
marked.setOptions({
renderer: new marked.Renderer(),
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false,
highlight: function (code, lang) {
//使用 highlight 插件解析文档中代码部分
return hljs.highlightAuto(code, [lang]).value;
}
});
</script>
<script>
function addColor() {
setTimeout(() => {
preCodeTohljs()
}, 200);
}
function preCodeTohljs() {
const code = $('pre').find('code')
code.each(function () {
$(this).addClass('hljs')
})
server()
}
</script>
<script>
function server() {
const loc = window.location.href
if (loc && loc.indexOf('http') >= 0) {
const a = $('#content').find('p').find('a')
a.each(function () {
const href = $(this).attr('href')
if (href && href.indexOf('cheere/rxfile-write') > 0) {
$(this).attr('href', 'javascript:;')
$(this).click(function () {
document.getElementById('content').innerHTML = ''
swithcEnZh = !swithcEnZh
mdToHtml()
})
}
})
}
}
</script>
</body>
</html>