Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function recolor() {
- let bf = document.querySelectorAll(".brainfuck");
- bf.forEach((code) => {
- var start = code.selectionStart;
- var end = code.selectionEnd;
- // console.log(start);
- let curCode = code.innerText;
- let newCode = "";
- let lastCode = '';
- for (let i = 0; i < curCode.length; i++) {
- let c = curCode.charAt(i);
- let codeType = 'comment';
- switch(c) {
- case '>':
- case '<':
- codeType = 'shift';
- break;
- case '.':
- case ',':
- codeType = 'io';
- break;
- case '[':
- case ']':
- codeType = 'loop';
- break;
- case '+':
- case '-':
- codeType = 'edit';
- break;
- }
- if (codeType != lastCode) {
- if (i != 0) {
- newCode += '</span>';
- }
- newCode += `<span class='${codeType}'>`;
- }
- newCode += c;
- lastCode = codeType;
- }
- newCode += "</span>";
- code.innerHTML = newCode;
- });
- }
- window.onload = () => {
- recolor();
- setInterval(()=> {
- recolor();
- }, 50);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement