mirror of
https://github.com/chinchang/web-maker.git
synced 2025-05-06 10:35:30 +02:00
load user script from external js file. fix #39
This commit is contained in:
parent
aadb2c1835
commit
3d74ce4cd7
@ -8,7 +8,7 @@
|
|||||||
"storage",
|
"storage",
|
||||||
"tabs"
|
"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": {
|
"options_ui": {
|
||||||
"page": "options.html",
|
"page": "options.html",
|
||||||
"chrome_style": true
|
"chrome_style": true
|
||||||
|
@ -619,35 +619,24 @@ settingsBtn, onboardModal, notificationsBtn, onboardShowInTabOptionBtn, onboardD
|
|||||||
+ '<style id="webmakerstyle">\n' + css + '\n</style>\n'
|
+ '<style id="webmakerstyle">\n' + css + '\n</style>\n'
|
||||||
+ '</head>\n'
|
+ '</head>\n'
|
||||||
+ '<body>\n' + html + '\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;
|
return contents;
|
||||||
}
|
}
|
||||||
function createPreviewFile(html, css, js) {
|
|
||||||
var contents = getCompleteHtml(html, css, js);
|
function writeFile(name, blob, cb) {
|
||||||
var fileWritten = false;
|
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); }
|
function errorHandler() { utils.log(arguments); }
|
||||||
|
|
||||||
window.webkitRequestFileSystem(window.TEMPORARY, 1024 * 1024 * 5, function(fs){
|
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) {
|
fileEntry.createWriter(function(fileWriter) {
|
||||||
function onWriteComplete() {
|
function onWriteComplete() {
|
||||||
if (fileWritten) {
|
if (fileWritten) {
|
||||||
frame.src = 'filesystem:chrome-extension://'
|
cb();
|
||||||
+ chrome.i18n.getMessage('@@extension_id') + '/temporary/' + 'preview.html';
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fileWritten = true;
|
fileWritten = true;
|
||||||
@ -662,6 +651,36 @@ settingsBtn, onboardModal, notificationsBtn, onboardShowInTabOptionBtn, onboardD
|
|||||||
}, errorHandler);
|
}, errorHandler);
|
||||||
}, errorHandler);
|
}, 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) {
|
scope.setPreviewContent = function (isForced) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user