1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-05-25 19:49:41 +02:00

move downloads permission to optionals. Fixes #139

This commit is contained in:
Kushagra Gour 2017-07-04 10:30:36 +05:30
parent 9aa2123b49
commit d429cd261f
2 changed files with 77 additions and 49 deletions

View File

@ -4,12 +4,8 @@
"manifest_version": 2,
"description": "Blazing fast & offline playground for your web experiments",
"homepage_url": "https://webmakerapp.com",
"permissions": [
"storage",
"tabs",
"<all_urls>",
"downloads"
],
"permissions": ["storage", "tabs", "<all_urls>"],
"optional_permissions": ["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'",
"options_ui": {
"page": "options.html",
@ -20,7 +16,7 @@
"default_icon": "icon-16.png"
},
"background": {
"scripts": [ "eventPage.js" ],
"scripts": ["eventPage.js"],
"persistent": false
},
"icons": {

View File

@ -1451,50 +1451,82 @@ runBtn, searchInput, consoleEl, consoleLogEl, logCountEl, fontStyleTag, fontStyl
);
}
scope.takeScreenshot = function(e) {
// 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));
}
function handleDownloadsPermission() {
var d = deferred();
chrome.permissions.contains(
{
permissions: ['downloads']
},
function(result) {
if (result) {
d.resolve();
} else {
chrome.permissions.request(
{
permissions: ['downloads']
},
function(granted) {
if (granted) {
trackEvent('fn', 'downloadsPermGiven');
d.resolve();
} else {
d.reject();
}
}
);
}
);
}, 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();
};