mirror of
https://github.com/MatMoul/quickdial-webext.git
synced 2024-12-23 15:36:12 +00:00
Bug reported by Acid Crash: Capture from new tab dont preserve ratio
This commit is contained in:
parent
15c1836e28
commit
733887fbcb
@ -145,7 +145,7 @@ core.SiteInfos.fromTab = function(callback){ // Retrieve infos from current tab.
|
|||||||
setTimeout(whaitLoaded, 300);
|
setTimeout(whaitLoaded, 300);
|
||||||
}, function(){ if(callback) callback(); });
|
}, function(){ if(callback) callback(); });
|
||||||
}
|
}
|
||||||
core.SiteInfos.fromNewTab1 = function(url, callback){ // Retrieve infos from a new tab. callback( { url, title, icon, screenshot } || error: callback() )
|
core.SiteInfos.fromNewTab = function(url, callback){ // Retrieve infos from a new tab. callback( { url, title, icon, screenshot } || error: callback() )
|
||||||
browser.tabs.create({url: url, active: false}).then(function(tab){
|
browser.tabs.create({url: url, active: false}).then(function(tab){
|
||||||
browser.tabs.update(tab.id, {muted: true}).then();
|
browser.tabs.update(tab.id, {muted: true}).then();
|
||||||
function whaitLoaded(){
|
function whaitLoaded(){
|
||||||
@ -153,33 +153,39 @@ core.SiteInfos.fromNewTab1 = function(url, callback){ // Retrieve infos from a
|
|||||||
if(tab.status == 'loading') setTimeout(whaitLoaded, 300);
|
if(tab.status == 'loading') setTimeout(whaitLoaded, 300);
|
||||||
else {
|
else {
|
||||||
browser.tabs.update(tab.id, {active: true}).then(function(){
|
browser.tabs.update(tab.id, {active: true}).then(function(){
|
||||||
console.log('Hello');
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
browser.tabs.captureVisibleTab().then(function(img){
|
browser.tabs.captureVisibleTab().then(function(img){
|
||||||
browser.tabs.remove(tab.id);
|
browser.tabs.remove(tab.id);
|
||||||
|
|
||||||
var previewWidth = 1200; // Need to be linked to settings
|
|
||||||
var previewHeight = 710; // Need to be linked to settings
|
|
||||||
var imgObj = new Image;
|
var imgObj = new Image;
|
||||||
imgObj.src = img;
|
imgObj.src = img;
|
||||||
|
|
||||||
|
var previewWidth = 1200; // Need to be linked to settings
|
||||||
|
var previewHeight = 710; // Need to be linked to settings
|
||||||
|
|
||||||
var canvas = document.createElement('canvas');
|
var canvas = document.createElement('canvas');
|
||||||
canvas.style.width = previewWidth.toString() + 'px';
|
canvas.style.width = previewWidth.toString() + 'px';
|
||||||
canvas.style.height = previewHeight.toString() + 'px';
|
canvas.style.height = previewHeight.toString() + 'px';
|
||||||
canvas.width = previewWidth / 2;
|
canvas.width = previewWidth / 2;
|
||||||
canvas.height = previewHeight / 2;
|
canvas.height = previewHeight / 2;
|
||||||
|
|
||||||
var ctx = canvas.getContext('2d');
|
var ctx = canvas.getContext('2d');
|
||||||
ctx.clearRect(0, 0, previewWidth, previewHeight);
|
ctx.clearRect(0, 0, previewWidth, previewHeight);
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.scale(0.5, 0.5);
|
ctx.scale(0.5, 0.5);
|
||||||
//ctx.drawImage(img, 0, 0, previewWidth, previewHeight, 'rgb(255, 255, 255)');
|
setTimeout(function(){
|
||||||
console.log(img);
|
if(tab.height * previewWidth / previewHeight >= tab.width){
|
||||||
ctx.drawImage(imgObj, 0, 0, 0, 0, 'rgb(255, 255, 255)');
|
// Cut the bottom of the page
|
||||||
|
ctx.drawImage(imgObj, 0, 0, tab.width, tab.width / previewWidth * previewHeight, 0, 0, previewWidth, previewHeight);
|
||||||
|
} else {
|
||||||
|
// Stretch or cutting right part of the page ? actualy Stretch
|
||||||
|
ctx.drawImage(imgObj, 0, 0, tab.width, tab.height, 0, 0, previewWidth, previewHeight);
|
||||||
|
//ctx.drawImage(imgObj, 0, 0, tab.height / previewHeight * previewWidth, tab.height, 0, 0, previewWidth, previewHeight);
|
||||||
|
}
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
img = canvas.toDataURL();
|
img = canvas.toDataURL();
|
||||||
|
|
||||||
|
|
||||||
if(callback) callback( { url: tab.url, title: tab.title, icon: tab.favIconUrl, screenshot: img } );
|
if(callback) callback( { url: tab.url, title: tab.title, icon: tab.favIconUrl, screenshot: img } );
|
||||||
|
}, 1);
|
||||||
}, function(){
|
}, function(){
|
||||||
browser.tabs.remove(tab.id);
|
browser.tabs.remove(tab.id);
|
||||||
if(callback) callback();
|
if(callback) callback();
|
||||||
@ -444,36 +450,16 @@ core.GridNodes.refreshNode = function(gridNode, callback){ // Refresh content of
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
core.GridNodes.capturePage = function(gridNode, callback){
|
core.GridNodes.capturePage = function(gridNode, callback){
|
||||||
browser.tabs.create({url: gridNode.url, active: false}).then(function(tab){
|
if(gridNode.__isLoading == true) return;
|
||||||
browser.tabs.update(tab.id, {muted: true}).then(function(){}, function(){});
|
gridNode.__isLoading = true;
|
||||||
function whaitLoaded(){
|
core.SiteInfos.fromNewTab(gridNode.url, function(infos){
|
||||||
browser.tabs.get(tab.id).then(function(tab){
|
if(infos){
|
||||||
if(tab.status == 'loading'){
|
gridNode.title = infos.title;
|
||||||
setTimeout(whaitLoaded, 300);
|
gridNode.image = infos.screenshot;
|
||||||
} else{
|
delete gridNode.__isLoading;
|
||||||
browser.tabs.update(tab.id, {active: true}).then(function(){
|
|
||||||
setTimeout(function(){
|
|
||||||
browser.tabs.captureVisibleTab().then(function(img){
|
|
||||||
browser.tabs.remove(tab.id);
|
|
||||||
gridNode.title = tab.title
|
|
||||||
gridNode.image = img;
|
|
||||||
core.GridNodes.saveNode(gridNode);
|
core.GridNodes.saveNode(gridNode);
|
||||||
if(callback) callback();
|
} else delete gridNode.__isLoading;
|
||||||
}, function(){
|
if(callback) callback(infos);
|
||||||
browser.tabs.remove(tab.id);
|
|
||||||
if(callback) callback();
|
|
||||||
});
|
|
||||||
}, 300);
|
|
||||||
}, function(){
|
|
||||||
if(callback) callback();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, function(){});
|
|
||||||
|
|
||||||
}
|
|
||||||
setTimeout(whaitLoaded, 1000);
|
|
||||||
}, function(){
|
|
||||||
if(callback) callback();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user