From 5ad7290b4acda2b3abf3b2796706a107cdc6095d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2?= Date: Tue, 4 Oct 2022 16:14:29 +0200 Subject: [PATCH] fixed sanbox --- public/script.js | 48 +++++++++++++++++++++++------------------------ script/prepare.js | 6 ++---- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/public/script.js b/public/script.js index b2eb9c1..99f8e0c 100644 --- a/public/script.js +++ b/public/script.js @@ -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; + } }; - diff --git a/script/prepare.js b/script/prepare.js index 621fda1..6d87f8a 100644 --- a/script/prepare.js +++ b/script/prepare.js @@ -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.'); });