1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-08-06 13:26:36 +02:00

add build

This commit is contained in:
Kushagra Gour
2017-11-19 02:09:49 +05:30
parent d2026d026e
commit 709c59f1b4
3 changed files with 455 additions and 250 deletions

129
dist/script.js vendored
View File

@@ -18,47 +18,52 @@
'use strict'; 'use strict';
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
// Delay registration until after the page has loaded, to ensure that our // Delay registration until after the page has loaded, to ensure that our
// precaching requests don't degrade the first visit experience. // precaching requests don't degrade the first visit experience.
// See https://developers.google.com/web/fundamentals/instant-and-offline/service-worker/registration // See https://developers.google.com/web/fundamentals/instant-and-offline/service-worker/registration
window.addEventListener('load', function() { window.addEventListener('load', function() {
// Your service-worker.js *must* be located at the top-level directory relative to your site. // Your service-worker.js *must* be located at the top-level directory relative to your site.
// It won't be able to control pages unless it's located at the same level or higher than them. // It won't be able to control pages unless it's located at the same level or higher than them.
// *Don't* register service worker file in, e.g., a scripts/ sub-directory! // *Don't* register service worker file in, e.g., a scripts/ sub-directory!
// See https://github.com/slightlyoff/ServiceWorker/issues/468 // See https://github.com/slightlyoff/ServiceWorker/issues/468
navigator.serviceWorker.register('service-worker.js').then(function(reg) { navigator.serviceWorker
// updatefound is fired if service-worker.js changes. .register('service-worker.js')
reg.onupdatefound = function() { .then(function(reg) {
// The updatefound event implies that reg.installing is set; see // updatefound is fired if service-worker.js changes.
// https://w3c.github.io/ServiceWorker/#service-worker-registration-updatefound-event reg.onupdatefound = function() {
var installingWorker = reg.installing; // The updatefound event implies that reg.installing is set; see
// https://w3c.github.io/ServiceWorker/#service-worker-registration-updatefound-event
var installingWorker = reg.installing;
installingWorker.onstatechange = function() { installingWorker.onstatechange = function() {
switch (installingWorker.state) { switch (installingWorker.state) {
case 'installed': case 'installed':
if (navigator.serviceWorker.controller) { if (navigator.serviceWorker.controller) {
// At this point, the old content will have been purged and the fresh content will // At this point, the old content will have been purged and the fresh content will
// have been added to the cache. // have been added to the cache.
// It's the perfect time to display a "New content is available; please refresh." // It's the perfect time to display a "New content is available; please refresh."
// message in the page's interface. // message in the page's interface.
console.log('New or updated content is available.'); console.log('New or updated content is available.');
} else { } else {
// At this point, everything has been precached. // At this point, everything has been precached.
// It's the perfect time to display a "Content is cached for offline use." message. // It's the perfect time to display a "Content is cached for offline use." message.
console.log('Content is now available offline!'); console.log('Content is now available offline!');
} }
break; break;
case 'redundant': case 'redundant':
console.error('The installing service worker became redundant.'); console.error(
break; 'The installing service worker became redundant.'
} );
}; break;
}; }
}).catch(function(e) { };
console.error('Error during service worker registration:', e); };
}); })
}); .catch(function(e) {
console.error('Error during service worker registration:', e);
});
});
} }
(function() { (function() {
@@ -1628,7 +1633,9 @@ globalConsoleContainerEl
contents += contents +=
'<script src="' + '<script src="' +
// chrome.extension.getURL('lib/screenlog.js') + (chrome.extension
? chrome.extension.getURL('lib/screenlog.js')
: `${location.origin}/lib/screenlog.js`) +
'"></script>'; '"></script>';
if (jsMode === JsModes.ES6) { if (jsMode === JsModes.ES6) {
@@ -1638,7 +1645,7 @@ globalConsoleContainerEl
'"></script>'; '"></script>';
} }
if (js) { if (js !== undefined) {
contents += '<script>\n' + js + '\n//# sourceURL=userscript.js'; contents += '<script>\n' + js + '\n//# sourceURL=userscript.js';
} else { } else {
var origin = chrome.i18n.getMessage() var origin = chrome.i18n.getMessage()
@@ -1706,7 +1713,8 @@ globalConsoleContainerEl
} }
function createPreviewFile(html, css, js) { function createPreviewFile(html, css, js) {
var contents = getCompleteHtml(html, css); const shouldInlineJs = !window.webkitRequestFileSystem;
var contents = getCompleteHtml(html, css, shouldInlineJs ? js : '');
var blob = new Blob([contents], { type: 'text/plain;charset=UTF-8' }); var blob = new Blob([contents], { type: 'text/plain;charset=UTF-8' });
var blobjs = new Blob([js], { type: 'text/plain;charset=UTF-8' }); var blobjs = new Blob([js], { type: 'text/plain;charset=UTF-8' });
@@ -1716,21 +1724,30 @@ globalConsoleContainerEl
trackEvent.hasTrackedCode = true; trackEvent.hasTrackedCode = true;
} }
// we need to store user script in external JS file to prevent inline-script if (shouldInlineJs) {
// CSP from affecting it. frame.src = frame.src;
writeFile('script.js', blobjs, function() { setTimeout(() => {
writeFile('preview.html', blob, function() { frame.contentDocument.open();
var origin = chrome.i18n.getMessage() frame.contentDocument.write(contents);
? `chrome-extension://${chrome.i18n.getMessage('@@extension_id')}` frame.contentDocument.close();
: `${location.origin}`; }, 10);
var src = `filesystem:${origin}/temporary/preview.html`; } else {
if (scope.detachedWindow) { // we need to store user script in external JS file to prevent inline-script
scope.detachedWindow.postMessage(src, '*'); // CSP from affecting it.
} else { writeFile('script.js', blobjs, function() {
frame.src = src; writeFile('preview.html', blob, function() {
} var origin = chrome.i18n.getMessage()
? `chrome-extension://${chrome.i18n.getMessage('@@extension_id')}`
: `${location.origin}`;
var src = `filesystem:${origin}/temporary/preview.html`;
if (scope.detachedWindow) {
scope.detachedWindow.postMessage(src, '*');
} else {
frame.src = src;
}
});
}); });
}); }
} }
scope.setPreviewContent = function(isForced) { scope.setPreviewContent = function(isForced) {

574
dist/service-worker.js vendored

File diff suppressed because one or more lines are too long

2
dist/style.css vendored
View File

@@ -977,4 +977,4 @@ while the theme CSS file is loading */
color: #D1EDFF; color: #D1EDFF;
} }
.cm-s-midnight .CodeMirror-gutters { background: #0F192A; border-right: 1px solid; } .cm-s-midnight .CodeMirror-gutters { background: #0F192A; border-right: 1px solid; }
.cm-s-midnight .CodeMirror-activeline-background { background: #253540; color: blue; } .cm-s-midnight .CodeMirror-activeline-background { background: #253540; }