Skip to content

Commit

Permalink
Merge pull request #33 from nicosh/code_highlighet
Browse files Browse the repository at this point in the history
fixed sanbox
  • Loading branch information
nicosh authored Oct 4, 2022
2 parents 08735d9 + 5ad7290 commit 537407e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
48 changes: 23 additions & 25 deletions public/script.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());
if(params.theme === "dark"){
document.getElementById("body").classList.remove('light');
document.getElementById("body").classList.add('dark');
}else{
document.getElementById("body").classList.remove('dark');
document.getElementById("body").classList.add('light');
if (params.theme === 'dark') {
document.getElementById('body').classList.remove('light');
document.getElementById('body').classList.add('dark');
} else {
document.getElementById('body').classList.remove('dark');
document.getElementById('body').classList.add('light');
}

hljs.configure({ ignoreUnescapedHTML: true })
hljs.configure({ ignoreUnescapedHTML: true });
const jar = CodeJar(document.querySelector('#editor'), hljs.highlightElement, { tab: '\t' });
jar.updateCode(`console.log("Hello there!")`)
// https://stackoverflow.com/questions/19846078/how-to-read-from-chromes-console-in-javascript
jar.updateCode(`console.log("Hello there!")`);
console.stdlog = console.log.bind(console);
console.logs = [];
console.log = function(){
console.logs.push(Array.from(arguments));
console.stdlog.apply(console, arguments);
return console.logs.join(",")
}
document.querySelector("#exec").onclick = (e)=>{
e.preventDefault()
console.logs.length = 0;
let code = jar.toString()
try {
let result = eval(code)
document.getElementById("output").innerHTML = result
} catch (error) {
document.getElementById("output").innerHTML = error
}
console.log = function () {
console.logs.push(Array.from(arguments));
console.stdlog.apply(console, arguments);
return console.logs.join(',');
};
document.querySelector('#exec').onclick = (e) => {
e.preventDefault();
console.logs.length = 0;
let code = jar.toString();
try {
let result = eval(code);
document.getElementById('output').innerHTML = result;
} catch (error) {
document.getElementById('output').innerHTML = error;
}
};

6 changes: 2 additions & 4 deletions script/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ const archiver = require('archiver');
const fs = require('fs');
const output = fs.createWriteStream('extension.zip');
const archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
zlib: { level: 9 }, // Sets the compression level.
});

// listen for all archive data to be written
// 'close' event is fired only when a file descriptor is involved
output.on('close', function() {
output.on('close', function () {
console.log(archive.pointer() + ' total bytes');
console.log('archiver has been finalized and the output file descriptor has closed.');
});
Expand Down

0 comments on commit 537407e

Please sign in to comment.