mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-14 02:26:20 +02:00
move downloads permission to optionals. Fixes #139
This commit is contained in:
@ -4,12 +4,8 @@
|
|||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"description": "Blazing fast & offline playground for your web experiments",
|
"description": "Blazing fast & offline playground for your web experiments",
|
||||||
"homepage_url": "https://webmakerapp.com",
|
"homepage_url": "https://webmakerapp.com",
|
||||||
"permissions": [
|
"permissions": ["storage", "tabs", "<all_urls>"],
|
||||||
"storage",
|
"optional_permissions": ["downloads"],
|
||||||
"tabs",
|
|
||||||
"<all_urls>",
|
|
||||||
"downloads"
|
|
||||||
],
|
|
||||||
"content_security_policy": "script-src 'self' filesystem: http://localhost:* https://localhost:* https://ajax.googleapis.com https://code.jquery.com https://cdnjs.cloudflare.com https://unpkg.com https://maxcdn.com https://cdn77.com https://maxcdn.bootstrapcdn.com https://cdn.jsdelivr.net/ https://*.stripe.com/ https://builds.framerjs.com/ https://rawgit.com https://wzrd.in https://www.google-analytics.com 'unsafe-eval'; object-src 'self'",
|
"content_security_policy": "script-src 'self' filesystem: http://localhost:* https://localhost:* https://ajax.googleapis.com https://code.jquery.com https://cdnjs.cloudflare.com https://unpkg.com https://maxcdn.com https://cdn77.com https://maxcdn.bootstrapcdn.com https://cdn.jsdelivr.net/ https://*.stripe.com/ https://builds.framerjs.com/ https://rawgit.com https://wzrd.in https://www.google-analytics.com 'unsafe-eval'; object-src 'self'",
|
||||||
"options_ui": {
|
"options_ui": {
|
||||||
"page": "options.html",
|
"page": "options.html",
|
||||||
@ -20,7 +16,7 @@
|
|||||||
"default_icon": "icon-16.png"
|
"default_icon": "icon-16.png"
|
||||||
},
|
},
|
||||||
"background": {
|
"background": {
|
||||||
"scripts": [ "eventPage.js" ],
|
"scripts": ["eventPage.js"],
|
||||||
"persistent": false
|
"persistent": false
|
||||||
},
|
},
|
||||||
"icons": {
|
"icons": {
|
||||||
|
116
src/script.js
116
src/script.js
@ -1451,50 +1451,82 @@ runBtn, searchInput, consoleEl, consoleLogEl, logCountEl, fontStyleTag, fontStyl
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
scope.takeScreenshot = function(e) {
|
function handleDownloadsPermission() {
|
||||||
// Hide tooltips so that they don't show in the screenshot
|
var d = deferred();
|
||||||
var s = document.createElement('style');
|
chrome.permissions.contains(
|
||||||
s.textContent =
|
{
|
||||||
'[class*="hint"]:after, [class*="hint"]:before { display: none!important; }';
|
permissions: ['downloads']
|
||||||
document.body.appendChild(s);
|
},
|
||||||
|
function(result) {
|
||||||
function onImgLoad(image) {
|
if (result) {
|
||||||
var c = document.createElement('canvas');
|
d.resolve();
|
||||||
var iframeBounds = frame.getBoundingClientRect();
|
} else {
|
||||||
c.width = iframeBounds.width;
|
chrome.permissions.request(
|
||||||
c.height = iframeBounds.height;
|
{
|
||||||
var ctx = c.getContext('2d');
|
permissions: ['downloads']
|
||||||
ctx.drawImage(
|
},
|
||||||
image,
|
function(granted) {
|
||||||
iframeBounds.left,
|
if (granted) {
|
||||||
iframeBounds.top,
|
trackEvent('fn', 'downloadsPermGiven');
|
||||||
iframeBounds.width,
|
d.resolve();
|
||||||
iframeBounds.height,
|
} else {
|
||||||
0,
|
d.reject();
|
||||||
0,
|
}
|
||||||
iframeBounds.width,
|
}
|
||||||
iframeBounds.height
|
);
|
||||||
);
|
|
||||||
image.removeEventListener('load', onImgLoad);
|
|
||||||
saveScreenshot(c.toDataURL());
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
chrome.tabs.captureVisibleTab(
|
|
||||||
null,
|
|
||||||
{ format: 'png', quality: 100 },
|
|
||||||
function(dataURI) {
|
|
||||||
s.remove();
|
|
||||||
if (dataURI) {
|
|
||||||
var image = new Image();
|
|
||||||
image.src = dataURI;
|
|
||||||
image.addEventListener('load', () => onImgLoad(image, dataURI));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
}, 50);
|
);
|
||||||
|
return d.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
scope.takeScreenshot = function(e) {
|
||||||
|
handleDownloadsPermission().then(() => {
|
||||||
|
// Hide tooltips so that they don't show in the screenshot
|
||||||
|
var s = document.createElement('style');
|
||||||
|
s.textContent =
|
||||||
|
'[class*="hint"]:after, [class*="hint"]:before { display: none!important; }';
|
||||||
|
document.body.appendChild(s);
|
||||||
|
|
||||||
|
function onImgLoad(image) {
|
||||||
|
var c = document.createElement('canvas');
|
||||||
|
var iframeBounds = frame.getBoundingClientRect();
|
||||||
|
c.width = iframeBounds.width;
|
||||||
|
c.height = iframeBounds.height;
|
||||||
|
var ctx = c.getContext('2d');
|
||||||
|
ctx.drawImage(
|
||||||
|
image,
|
||||||
|
iframeBounds.left,
|
||||||
|
iframeBounds.top,
|
||||||
|
iframeBounds.width,
|
||||||
|
iframeBounds.height,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
iframeBounds.width,
|
||||||
|
iframeBounds.height
|
||||||
|
);
|
||||||
|
image.removeEventListener('load', onImgLoad);
|
||||||
|
saveScreenshot(c.toDataURL());
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
chrome.tabs.captureVisibleTab(
|
||||||
|
null,
|
||||||
|
{ format: 'png', quality: 100 },
|
||||||
|
function(dataURI) {
|
||||||
|
s.remove();
|
||||||
|
if (dataURI) {
|
||||||
|
var image = new Image();
|
||||||
|
image.src = dataURI;
|
||||||
|
image.addEventListener('load', () => onImgLoad(image, dataURI));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}, 50);
|
||||||
|
|
||||||
|
trackEvent('ui', 'takeScreenshotBtnClick');
|
||||||
|
});
|
||||||
|
|
||||||
trackEvent('ui', 'takeScreenshotBtnClick');
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user