-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
npm.js
57 lines (52 loc) · 2.04 KB
/
npm.js
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
import DannyDeVito from "./dist/index"
document.addEventListener(`DOMContentLoaded`, e => {
// Converter
const converter = new DannyDeVito()
const meters = document.getElementById(`metersInput`)
const devitos = document.getElementById(`devitosInput`)
meters.addEventListener(`input`, e => {
devitos.value = converter.toDevitos(meters.value, 6).toString()
})
devitos.addEventListener(`input`, e => {
meters.value = converter.toMeters(devitos.value, 6).toString()
})
// Page style
const htmlCodes = document.querySelectorAll(`pre.html`)
htmlCodes.forEach(htmlCode => {
let lt = htmlCode.innerHTML
let regex = /(".+?")/g
const htmlString = lt.replace(regex, '<span class="html-string">$&</span>')
htmlCode.innerHTML = htmlString
lt = htmlCode.innerHTML
regex = /(<[0-z]+?>)|(<[a-z]+\S)|(<\/[0-z]+?>)|(>)/gi
const htmlTags = lt.replace(regex, '<span class="html-tag">$&</span>')
htmlCode.innerHTML = htmlTags
lt = htmlCode.innerHTML
regex = /(id)|(src)/g
const htmlAttr = lt.replace(regex, '<span class="html-attr">$&</span>')
htmlCode.innerHTML = htmlAttr
})
const jsCodes = document.querySelectorAll(`pre.javascript`)
jsCodes.forEach(jsCode => {
let lt = jsCode.innerHTML
let regex = /(span)|(converter)/gi
const jsVarName = lt.replace(regex, '<span class="js-vName">$&</span>')
jsCode.innerHTML = jsVarName
lt = jsCode.innerHTML
regex = /(const)|(var)|(let)|(new)/g
const jsVar = lt.replace(regex, '<span class="js-var">$&</span>')
jsCode.innerHTML = jsVar
lt = jsCode.innerHTML
regex = /[0-9]+?|(`.+?`)/gi
const jsNum = lt.replace(regex, '<span class="js-num">$&</span>')
jsCode.innerHTML = jsNum
lt = jsCode.innerHTML
regex = /(toMeters)|(getElementById)/g
const jsFunc = lt.replace(regex, '<span class="js-func">$&</span>')
jsCode.innerHTML = jsFunc
lt = jsCode.innerHTML
regex = /(DannyDeVito)/g
const jsClass = lt.replace(regex, '<span class="js-class">$&</span>')
jsCode.innerHTML = jsClass
})
})