Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Hope41 committed Jun 5, 2024
1 parent aba81f2 commit 4d27760
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function pressPost() {

window.onload = () => {
const code = document.querySelectorAll('.code')
const codeBig = document.querySelectorAll('.codeBig')
const year = document.querySelector('.year')
const form = document.getElementById('form')

Expand Down Expand Up @@ -58,32 +57,29 @@ window.onload = () => {
if (localStorage.getItem(KEY) == 'light') toggleTheme()

// Highlight code
const highlight = cde => {
for (let i = 0; i < cde.length; i ++) {
const box = cde[i]
const lines = box.textContent.split('¬')
let isGrayed = false

for (let i = 0; i < lines.length; i ++) {
if (isGrayed) lines[i] = '<span class = gray>' + lines[i] + '</span>'
else {
lines[i] = lines[i]
.replace(/(\/\/.*)/g, '<span class = comment>$1</span>')
.replace(/(\'.*\')/g, '<span class = string>$1</span>')
.replace(/(\b\d+\b|\.)/g, '<span class = number>$1</span>')
.replace(/(function)(.*)(\()/g, 'function<span class = name>$2</span>(')
.replace(/(requestAnimationFrame|confirm|alert)/g, '<span class = name>$1</span>')

lines[i] = lines[i]
.replace(/\b(if|else|return|function|const|let|for|in|of|break|continue)\b/g,
'<span class = keyword>$1</span>')
}

isGrayed = !isGrayed
for (let i = 0; i < code.length; i ++) {
const box = code[i]
const lines = box.textContent.split('¬')
let isGrayed = false

for (let i = 0; i < lines.length; i ++) {
if (isGrayed) lines[i] = '<span class = gray>' + lines[i] + '</span>'
else {
lines[i] = lines[i]
.replace(/\</g, '&lt;')
.replace(/(\/\/.*)/g, '<span class = comment>$1</span>')
.replace(/(\'.*\')/g, '<span class = string>$1</span>')
.replace(/(\b\d+\b|\.)/g, '<span class = number>$1</span>')
.replace(/(function)(.*)(\()/g, 'function<span class = name>$2</span>(')
.replace(/(requestAnimationFrame|confirm|alert)/g, '<span class = name>$1</span>')

lines[i] = lines[i]
.replace(/\b(if|else|return|function|const|let|for|in|of|break|continue)\b/g,
'<span class = keyword>$1</span>')
}
box.innerHTML = lines.join('')

isGrayed = !isGrayed
}
box.innerHTML = lines.join('')
}
highlight(code)
highlight(codeBig)
}

0 comments on commit 4d27760

Please sign in to comment.