1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-05-05 10:05:18 +02:00

load user script from external js file. fix #39

This commit is contained in:
Kushagra Gour 2017-01-09 11:59:52 +05:30
parent aadb2c1835
commit 3d74ce4cd7
2 changed files with 39 additions and 20 deletions

View File

@ -8,7 +8,7 @@
"storage",
"tabs"
],
"content_security_policy": "script-src 'self' https://www.google-analytics.com 'unsafe-eval'; object-src 'self'",
"content_security_policy": "script-src 'self' https://ajax.googleapis.com https://code.jquery.com https://cdnjs.cloudflare.com https://unpkg.com https://maxcdn.bootstrapcdn.com https://cdn.jsdelivr.net/ https://www.google-analytics.com 'unsafe-eval'; object-src 'self'",
"options_ui": {
"page": "options.html",
"chrome_style": true

View File

@ -619,35 +619,24 @@ settingsBtn, onboardModal, notificationsBtn, onboardShowInTabOptionBtn, onboardD
+ '<style id="webmakerstyle">\n' + css + '\n</style>\n'
+ '</head>\n'
+ '<body>\n' + html + '\n'
+ externalJs + '\n<script>\n' + js + '\n//# sourceURL=userscript.js</script></body>\n</html>';
+ externalJs + '\n<script src="'
+ 'filesystem:chrome-extension://'
+ chrome.i18n.getMessage('@@extension_id') + '/temporary/' + 'script.js' + '">\n'
+ '</script></body>\n</html>';
return contents;
}
function createPreviewFile(html, css, js) {
var contents = getCompleteHtml(html, css, js);
function writeFile(name, blob, cb) {
var fileWritten = false;
var blob = new Blob([ contents ], { type: "text/plain;charset=UTF-8" });
// Track if people have written code.
if (!trackEvent.hasTrackedCode && (html || css || js)) {
trackEvent('fn', 'hasCode');
trackEvent.hasTrackedCode = true;
}
// Track when people actually are working.
trackEvent.previewCount = (trackEvent.previewCount || 0) + 1;
if (trackEvent.previewCount === 4) {
trackEvent('fn', 'usingPreview');
}
function errorHandler() { utils.log(arguments); }
window.webkitRequestFileSystem(window.TEMPORARY, 1024 * 1024 * 5, function(fs){
fs.root.getFile('preview.html', { create: true }, function(fileEntry) {
fs.root.getFile(name, { create: true }, function(fileEntry) {
fileEntry.createWriter(function(fileWriter) {
function onWriteComplete() {
if (fileWritten) {
frame.src = 'filesystem:chrome-extension://'
+ chrome.i18n.getMessage('@@extension_id') + '/temporary/' + 'preview.html';
cb();
}
else {
fileWritten = true;
@ -662,6 +651,36 @@ settingsBtn, onboardModal, notificationsBtn, onboardShowInTabOptionBtn, onboardD
}, errorHandler);
}, errorHandler);
}, errorHandler);
}
function createPreviewFile(html, css, js) {
var contents = getCompleteHtml(html, css, js);
var fileWritten = false;
var blob = new Blob([ contents ], { type: "text/plain;charset=UTF-8" });
var blobjs = new Blob([ js ], { type: "text/plain;charset=UTF-8" });
// Track if people have written code.
if (!trackEvent.hasTrackedCode && (html || css || js)) {
trackEvent('fn', 'hasCode');
trackEvent.hasTrackedCode = true;
}
// Track when people actually are working.
trackEvent.previewCount = (trackEvent.previewCount || 0) + 1;
if (trackEvent.previewCount === 4) {
trackEvent('fn', 'usingPreview');
}
// we need to store user script in external JS file to prevent inline-script
// CSP from affecting it.
writeFile('script.js', blobjs, function () {
writeFile('preview.html', blob, function () {
frame.src = 'filesystem:chrome-extension://'
+ chrome.i18n.getMessage('@@extension_id') + '/temporary/' + 'preview.html';
});
});
}
scope.setPreviewContent = function (isForced) {