mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-13 18:16:19 +02:00
move downloads permission to optionals. Fixes #139
This commit is contained in:
116
src/script.js
116
src/script.js
@ -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();
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user