mirror of
https://github.com/MatMoul/quickdial-webext.git
synced 2024-12-23 15:36:12 +00:00
Large change
This commit is contained in:
parent
cb544703ad
commit
34f788fdf3
@ -111,17 +111,75 @@ core.Bookmarks.getItem = function(bookmarkItem, path){ // Return BookmarkItem fr
|
|||||||
}
|
}
|
||||||
|
|
||||||
core.SiteInfos = {} // Siteinfos helper object
|
core.SiteInfos = {} // Siteinfos helper object
|
||||||
core.SiteInfos.loadInfos = function(url, args, callback){ // args: { icon: false; screenshot: false }, callback( { url, title, (/!\ Not handled now)icon, screenshot } || error: {} )
|
core.SiteInfos.fromTab = function(callback){ // Retrieve infos from current tab. callback( { url, title, icon, screenshot } || error: callback() )
|
||||||
|
browser.tabs.getCurrent().then(function(tab){
|
||||||
|
function whaitLoaded(){
|
||||||
|
browser.tabs.get(tab.id).then(function(tab){
|
||||||
|
if(tab.status == 'loading') setTimeout(whaitLoaded, 300);
|
||||||
|
else{
|
||||||
|
browser.tabs.update(tab.id, {active: true}).then(function(){
|
||||||
|
setTimeout(function(){
|
||||||
|
browser.tabs.captureVisibleTab().then(function(img){
|
||||||
|
browser.tabs.remove(tab.id);
|
||||||
|
if(callback) callback( { url: tab.url, title: tab.title, icon: tab.favIconUrl, screenshot: img } );
|
||||||
|
}, function(){
|
||||||
|
browser.tabs.remove(tab.id);
|
||||||
|
if(callback) callback();
|
||||||
|
});
|
||||||
|
}, 300);
|
||||||
|
}, function(){
|
||||||
|
if(callback) callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, function(){
|
||||||
|
if(callback) callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
setTimeout(whaitLoaded, 300);
|
||||||
|
}, function(){
|
||||||
|
if(callback) 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.update(tab.id, {muted: true}).then();
|
||||||
|
function whaitLoaded(){
|
||||||
|
browser.tabs.get(tab.id).then(function(tab){
|
||||||
|
if(tab.status == 'loading') setTimeout(whaitLoaded, 300);
|
||||||
|
else{
|
||||||
|
browser.tabs.update(tab.id, {active: true}).then(function(){
|
||||||
|
setTimeout(function(){
|
||||||
|
browser.tabs.captureVisibleTab().then(function(img){
|
||||||
|
browser.tabs.remove(tab.id);
|
||||||
|
if(callback) callback( { url: tab.url, title: tab.title, icon: tab.favIconUrl, screenshot: img } );
|
||||||
|
}, function(){
|
||||||
|
browser.tabs.remove(tab.id);
|
||||||
|
if(callback) callback();
|
||||||
|
});
|
||||||
|
}, 300);
|
||||||
|
}, function(){
|
||||||
|
if(callback) callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, function(){
|
||||||
|
if(callback) callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
setTimeout(whaitLoaded, 300);
|
||||||
|
}, function(){
|
||||||
|
if(callback) callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
core.SiteInfos.fromFrame = function(url, callback){ // Retrieve infos from an iframe. callback( { url, title, (/!\ Not handled now)icon, screenshot } || error: callback() )
|
||||||
function pageLoaded(){
|
function pageLoaded(){
|
||||||
if(!iframe) return;
|
if(!iframe) return;
|
||||||
var docTitle = iframe.contentWindow.document.title;
|
var docTitle = iframe.contentWindow.document.title;
|
||||||
var docIcon = null;
|
var docIcon = null;
|
||||||
var docScreenshot = null;
|
var docScreenshot = null;
|
||||||
|
//title
|
||||||
if(docTitle == '') docTitle = url;
|
if(docTitle == '') docTitle = url;
|
||||||
if(args && args.icon){
|
//icon
|
||||||
//
|
//screenshot
|
||||||
}
|
|
||||||
if(args && args.screenshot){
|
|
||||||
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';
|
||||||
@ -134,7 +192,6 @@ core.SiteInfos.loadInfos = function(url, args, callback){ // args: { icon: false
|
|||||||
ctx.drawWindow(iframe.contentWindow, 0, 0, previewWidth, previewHeight, 'rgb(255, 255, 255)');
|
ctx.drawWindow(iframe.contentWindow, 0, 0, previewWidth, previewHeight, 'rgb(255, 255, 255)');
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
docScreenshot = canvas.toDataURL();
|
docScreenshot = canvas.toDataURL();
|
||||||
}
|
|
||||||
|
|
||||||
document.body.removeChild(iframe);
|
document.body.removeChild(iframe);
|
||||||
iframe = null;
|
iframe = null;
|
||||||
@ -149,15 +206,14 @@ core.SiteInfos.loadInfos = function(url, args, callback){ // args: { icon: false
|
|||||||
xmlHttp.open('GET', url, true);
|
xmlHttp.open('GET', url, true);
|
||||||
xmlHttp.onload = function(){
|
xmlHttp.onload = function(){
|
||||||
iframe = document.createElement('iframe');
|
iframe = document.createElement('iframe');
|
||||||
iframe.referrerPolicy = "unsafe-url";
|
|
||||||
iframe.width = previewWidth
|
iframe.width = previewWidth
|
||||||
iframe.height = previewHeight
|
iframe.height = previewHeight
|
||||||
iframe.style.position = 'absolute';
|
iframe.style.position = 'absolute';
|
||||||
iframe.style.visibility = 'hidden';
|
//iframe.style.visibility = 'hidden';
|
||||||
document.body.appendChild(iframe);
|
|
||||||
var content = xmlHttp.responseText.replace('<head>', '<head><base href="' + url + '">');
|
var content = xmlHttp.responseText.replace('<head>', '<head><base href="' + url + '">');
|
||||||
iframe.srcdoc = content;
|
|
||||||
iframe.onload = function(){ pageLoaded(); }
|
iframe.onload = function(){ pageLoaded(); }
|
||||||
|
document.body.appendChild(iframe);
|
||||||
|
iframe.srcdoc = content;
|
||||||
setTimeout(function(){ pageLoaded(); }, 6000);
|
setTimeout(function(){ pageLoaded(); }, 6000);
|
||||||
}
|
}
|
||||||
xmlHttp.onabort = function(){ if(callback) callback(); }
|
xmlHttp.onabort = function(){ if(callback) callback(); }
|
||||||
@ -165,6 +221,10 @@ core.SiteInfos.loadInfos = function(url, args, callback){ // args: { icon: false
|
|||||||
xmlHttp.ontimeout = function(){ if(callback) callback(); }
|
xmlHttp.ontimeout = function(){ if(callback) callback(); }
|
||||||
xmlHttp.send();
|
xmlHttp.send();
|
||||||
}
|
}
|
||||||
|
core.SiteInfos.fromWS = function(url, callback){ // Retrieve infos from a Web Service. callback( { url, title, (/!\ Not handled now)icon, screenshot } || error: callback() )
|
||||||
|
console.log('Not implemented');
|
||||||
|
return core.SiteInfos.fromFrame(url, callback);
|
||||||
|
}
|
||||||
|
|
||||||
core.GridNodes = {}; // GridNodes helper object
|
core.GridNodes = {}; // GridNodes helper object
|
||||||
core.GridNodes.sync = function(gridNode, rootPath){ // Sync GridNodes with Bookmarks
|
core.GridNodes.sync = function(gridNode, rootPath){ // Sync GridNodes with Bookmarks
|
||||||
@ -237,7 +297,7 @@ core.GridNodes.getNode = function(gridNode, path){ // Return GridNode from RootG
|
|||||||
core.GridNodes.refreshNode = function(gridNode, callback){ // Refresh content of a GridNode
|
core.GridNodes.refreshNode = function(gridNode, callback){ // Refresh content of a GridNode
|
||||||
if(gridNode.__isLoading == true) return;
|
if(gridNode.__isLoading == true) return;
|
||||||
gridNode.__isLoading = true;
|
gridNode.__isLoading = true;
|
||||||
core.SiteInfos.loadInfos(gridNode.url, { screenshot: true }, function(infos){
|
core.SiteInfos.fromFrame(gridNode.url, function(infos){
|
||||||
if(infos){
|
if(infos){
|
||||||
gridNode.title = infos.title;
|
gridNode.title = infos.title;
|
||||||
gridNode.image = infos.screenshot;
|
gridNode.image = infos.screenshot;
|
||||||
@ -280,12 +340,17 @@ core.GridNodes.setNodeIndex = function(gridNode, index, newIndex, callback){ //
|
|||||||
}
|
}
|
||||||
core.GridNodes.capturePage = function(gridNode, callback){
|
core.GridNodes.capturePage = function(gridNode, callback){
|
||||||
browser.tabs.create({url: gridNode.url, active: false}).then(function(tab){
|
browser.tabs.create({url: gridNode.url, active: false}).then(function(tab){
|
||||||
setTimeout(function(){
|
browser.tabs.update(tab.id, {muted: true}).then(function(){}, function(){});
|
||||||
tab.active = true;
|
function whaitLoaded(){
|
||||||
|
browser.tabs.get(tab.id).then(function(tab){
|
||||||
|
if(tab.status == 'loading'){
|
||||||
|
setTimeout(whaitLoaded, 300);
|
||||||
|
} else{
|
||||||
browser.tabs.update(tab.id, {active: true}).then(function(){
|
browser.tabs.update(tab.id, {active: true}).then(function(){
|
||||||
|
setTimeout(function(){
|
||||||
browser.tabs.captureVisibleTab().then(function(img){
|
browser.tabs.captureVisibleTab().then(function(img){
|
||||||
//gridNode.title = tab.title
|
|
||||||
browser.tabs.remove(tab.id);
|
browser.tabs.remove(tab.id);
|
||||||
|
gridNode.title = tab.title
|
||||||
gridNode.image = img;
|
gridNode.image = img;
|
||||||
browser.bookmarks.update(gridNode.id, {
|
browser.bookmarks.update(gridNode.id, {
|
||||||
title: gridNode.title
|
title: gridNode.title
|
||||||
@ -297,10 +362,15 @@ core.GridNodes.capturePage = function(gridNode, callback){
|
|||||||
browser.tabs.remove(tab.id);
|
browser.tabs.remove(tab.id);
|
||||||
if(callback) callback();
|
if(callback) callback();
|
||||||
});
|
});
|
||||||
|
}, 300);
|
||||||
}, function(){
|
}, function(){
|
||||||
if(callback) callback();
|
if(callback) callback();
|
||||||
});
|
});
|
||||||
}, 4000);
|
}
|
||||||
|
}, function(){});
|
||||||
|
|
||||||
|
}
|
||||||
|
setTimeout(whaitLoaded, 300);
|
||||||
}, function(){
|
}, function(){
|
||||||
if(callback) callback();
|
if(callback) callback();
|
||||||
});
|
});
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
"<all_urls>"
|
"<all_urls>"
|
||||||
],
|
],
|
||||||
|
|
||||||
"content_security_policy": "default-src * moz-extension: 'self' 'unsafe-inline' 'unsafe-eval'; script-src * moz-extension: 'self' 'unsafe-inline' 'unsafe-eval'; child-src * moz-extension: 'self' 'unsafe-inline' 'unsafe-eval'; frame-src * moz-extension: 'self' 'unsafe-inline' 'unsafe-eval'; object-src * moz-extension: 'self' 'unsafe-inline' 'unsafe-eval'; style-src * moz-extension: 'self' 'unsafe-inline' 'unsafe-eval'",
|
|
||||||
|
|
||||||
"background": {
|
"background": {
|
||||||
"scripts": ["js/background.js"]
|
"scripts": ["js/background.js"]
|
||||||
},
|
},
|
||||||
|
BIN
src/src.zip
BIN
src/src.zip
Binary file not shown.
9
src/test/test.html
Normal file
9
src/test/test.html
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Security-Policy" content="default-src * 'self'; script-src * 'self'; child-src * 'self'; object-src * 'self'">
|
||||||
|
<script src="test.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<iframe id="iframe"></iframe>
|
||||||
|
</body>
|
||||||
|
</html>
|
21
src/test/test.js
Normal file
21
src/test/test.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
var url = 'https://www.matmoul.ch';
|
||||||
|
var xmlHttp = new XMLHttpRequest();
|
||||||
|
xmlHttp.timeout = 10000
|
||||||
|
xmlHttp.open('GET', url, true);
|
||||||
|
//xmlHttp.setRequestHeader('X-PINGOTHER', 'pingpong');
|
||||||
|
//xmlHttp.setRequestHeader('Content-Type', 'text/plain');
|
||||||
|
//xmlHttp.setRequestHeader('Access-Control-Request-Method', '*');
|
||||||
|
//xmlHttp.setRequestHeader('Origin', url);
|
||||||
|
//xmlHttp.setRequestHeader('Access-Control-Allow-Origin', '*');
|
||||||
|
xmlHttp.onload = function(){
|
||||||
|
iframe = document.getElementById('iframe');
|
||||||
|
iframe.width = 800
|
||||||
|
iframe.height = 600
|
||||||
|
iframe.style.position = 'absolute';
|
||||||
|
//iframe.style.visibility = 'hidden';
|
||||||
|
var content = xmlHttp.responseText.replace('<head>', '<head><base href="' + url + '">');
|
||||||
|
//iframe.onload = function(){ pageLoaded(); }
|
||||||
|
//document.body.appendChild(iframe);
|
||||||
|
iframe.srcdoc = content;
|
||||||
|
}
|
||||||
|
xmlHttp.send();
|
Loading…
Reference in New Issue
Block a user