(code, text, typingOn = true)
| 424 | } |
| 425 | |
| 426 | async function createCode(code, text, typingOn = true) { |
| 427 | const p = document.createElement("p"); |
| 428 | app.appendChild(p); |
| 429 | |
| 430 | const typing = localStorage.getItem("typing"); |
| 431 | |
| 432 | if (!typingOn || (typing && typing === "off")) { |
| 433 | p.innerHTML = `<span class="code">${code} =></span> ${text}`; |
| 434 | return; |
| 435 | } |
| 436 | |
| 437 | const typingSpeed = localStorage.getItem("typingSpeed") || 20; |
| 438 | |
| 439 | const span = document.createElement("span"); |
| 440 | span.className = "code" |
| 441 | p.appendChild(span); |
| 442 | p.scrollIntoView({ behavior: 'smooth' }); |
| 443 | let index = 0; |
| 444 | async function writeCode() { |
| 445 | while (index < code.length) { |
| 446 | span.innerHTML += code[index++]; |
| 447 | await new Promise((writeCode) => setTimeout(writeCode, typingSpeed)); |
| 448 | } |
| 449 | return; |
| 450 | } |
| 451 | await writeCode(); |
| 452 | |
| 453 | p.innerHTML += " " |
| 454 | |
| 455 | index = 0; |
| 456 | async function writeText() { |
| 457 | while (index < text.length) { |
| 458 | p.innerHTML += text[index++]; |
| 459 | await new Promise((writeText) => setTimeout(writeText, typingSpeed)); |
| 460 | } |
| 461 | return; |
| 462 | } |
| 463 | |
| 464 | await writeText(); |
| 465 | |
| 466 | } |
| 467 | |
| 468 | function downloadFile() { |
| 469 | let link = document.createElement("a"); |
no test coverage detected