diff --git a/client/components/Nav.js b/client/components/Nav.js index 13950578..3fa29e7f 100644 --- a/client/components/Nav.js +++ b/client/components/Nav.js @@ -65,7 +65,8 @@ function Nav(props) {

); - } else { + } + if (!props.user.authenticated) { return (
  • diff --git a/client/modules/IDE/components/PreviewFrame.js b/client/modules/IDE/components/PreviewFrame.js index 228c5f8d..a62e7127 100644 --- a/client/modules/IDE/components/PreviewFrame.js +++ b/client/modules/IDE/components/PreviewFrame.js @@ -3,20 +3,26 @@ import ReactDOM from 'react-dom'; import escapeStringRegexp from 'escape-string-regexp'; import srcDoc from 'srcdoc-polyfill'; + +const startTag = 'filestart-'; + function getAllScriptOffsets(htmlFile) { - var offs = []; - var found = true; - var lastInd = 0; - var startTag = 'filestart-'; + const offs = []; + let found = true; + let lastInd = 0; + let ind = 0; + let endFilenameInd = 0; + let filename = ''; + let lineOffset = 0; while (found) { - var ind = htmlFile.indexOf(startTag, lastInd); - if (ind == -1) { + ind = htmlFile.indexOf(startTag, lastInd); + if (ind === -1) { found = false; } else { - var endFilenameInd = htmlFile.indexOf('.js', ind+startTag.length); - var filename = htmlFile.substring(ind+startTag.length, endFilenameInd); - var lineOffset = htmlFile.substring(0, ind).split('\n').length; - offs.push([lineOffset, filename+'.js']); + endFilenameInd = htmlFile.indexOf('.js', ind + startTag.length + 3); + filename = htmlFile.substring(ind + startTag.length, endFilenameInd); + lineOffset = htmlFile.substring(0, ind).split('\n').length; + offs.push([lineOffset, filename]); lastInd = ind + 1; } } @@ -24,10 +30,9 @@ function getAllScriptOffsets(htmlFile) { } function hijackConsoleScript(offs) { - return ``; + return s; } class PreviewFrame extends React.Component { @@ -134,6 +140,7 @@ class PreviewFrame extends React.Component { injectLocalFiles() { let htmlFile = this.props.htmlFile.content; + let scriptOffs = []; // have to build the array manually because the spread operator is only // one level down... @@ -141,9 +148,10 @@ class PreviewFrame extends React.Component { this.props.jsFiles.forEach(jsFile => { const newJSFile = { ...jsFile }; let jsFileStrings = newJSFile.content.match(/(['"])((\\\1|.)*?)\1/gm); + const jsFileRegex = /^('|")(?!(http:\/\/|https:\/\/)).*\.(png|jpg|jpeg|gif|bmp|mp3|wav|aiff|ogg|json)('|")$/i; jsFileStrings = jsFileStrings || []; jsFileStrings.forEach(jsFileString => { - if (jsFileString.match(/^('|")(?!(http:\/\/|https:\/\/)).*\.(png|jpg|jpeg|gif|bmp|mp3|wav|aiff|ogg|json)('|")$/i)) { + if (jsFileString.match(jsFileRegex)) { const filePath = jsFileString.substr(1, jsFileString.length - 2); let fileName = filePath; if (fileName.match(/^\.\//)) { @@ -164,7 +172,8 @@ class PreviewFrame extends React.Component { jsFiles.forEach(jsFile => { const fileName = escapeStringRegexp(jsFile.name); const fileRegex = new RegExp(`([\s\S]*?)<\/script>`, 'gmi'); - htmlFile = htmlFile.replace(fileRegex, ``); + const replacementString = ``; + htmlFile = htmlFile.replace(fileRegex, replacementString); }); this.props.cssFiles.forEach(cssFile => { @@ -185,7 +194,7 @@ class PreviewFrame extends React.Component { htmlFile = htmlFile.replace(/(?:)([\s\S]*?)(?:<\/head>)/gmi, `\n${htmlHeadContents}\n`); } - var scriptOffs = getAllScriptOffsets(htmlFile); + scriptOffs = getAllScriptOffsets(htmlFile); htmlFile += hijackConsoleScript(JSON.stringify(scriptOffs)); return htmlFile;