mirror of
https://github.com/MatMoul/quickdial-webext.git
synced 2024-12-23 15:36:12 +00:00
Improvement
This commit is contained in:
parent
bae64a63b1
commit
cb544703ad
@ -112,10 +112,12 @@ 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.loadInfos = function(url, args, callback){ // args: { icon: false; screenshot: false }, callback( { url, title, (/!\ Not handled now)icon, screenshot } || error: {} )
|
||||||
function pageLoaded(last){
|
function pageLoaded(){
|
||||||
|
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;
|
||||||
|
if(docTitle == '') docTitle = url;
|
||||||
if(args && args.icon){
|
if(args && args.icon){
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
@ -134,26 +136,29 @@ core.SiteInfos.loadInfos = function(url, args, callback){ // args: { icon: false
|
|||||||
docScreenshot = canvas.toDataURL();
|
docScreenshot = canvas.toDataURL();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(last) document.body.removeChild(iframe);
|
document.body.removeChild(iframe);
|
||||||
|
iframe = null;
|
||||||
if(callback) callback({ url: url, title: docTitle, icon: docIcon, screenshot:docScreenshot });
|
if(callback) callback({ url: url, title: docTitle, icon: docIcon, screenshot:docScreenshot });
|
||||||
}
|
}
|
||||||
|
|
||||||
var previewWidth = 1200; // Need to be linked to settings
|
var previewWidth = 1200; // Need to be linked to settings
|
||||||
var previewHeight = 710; // Need to be linked to settings
|
var previewHeight = 710; // Need to be linked to settings
|
||||||
var iframe = document.createElement('iframe');
|
var iframe;
|
||||||
iframe.width = previewWidth
|
|
||||||
iframe.height = previewHeight
|
|
||||||
iframe.style.position = 'absolute';
|
|
||||||
iframe.style.visibility = 'hidden';
|
|
||||||
var xmlHttp = new XMLHttpRequest();
|
var xmlHttp = new XMLHttpRequest();
|
||||||
xmlHttp.timeout = 10000
|
xmlHttp.timeout = 10000
|
||||||
xmlHttp.open('GET', url, true);
|
xmlHttp.open('GET', url, true);
|
||||||
xmlHttp.onload = function(){
|
xmlHttp.onload = function(){
|
||||||
|
iframe = document.createElement('iframe');
|
||||||
|
iframe.referrerPolicy = "unsafe-url";
|
||||||
|
iframe.width = previewWidth
|
||||||
|
iframe.height = previewHeight
|
||||||
|
iframe.style.position = 'absolute';
|
||||||
|
iframe.style.visibility = 'hidden';
|
||||||
document.body.appendChild(iframe);
|
document.body.appendChild(iframe);
|
||||||
iframe.srcdoc = xmlHttp.responseText.replace('<head>', '<head><base href="' + url + '">');
|
var content = xmlHttp.responseText.replace('<head>', '<head><base href="' + url + '">');
|
||||||
//iframe.srcdoc = xmlHttp.responseText.replace('<head>', '<head><base href="' + url + '"><script>window.top = window;</script>');
|
iframe.srcdoc = content;
|
||||||
setTimeout(function(){ pageLoaded(); }, 2000); // /!\ Caution function can be shortcuted and sendtimeout is not the best way
|
iframe.onload = function(){ pageLoaded(); }
|
||||||
setTimeout(function(){ pageLoaded(true); }, 6000); // /!\ Caution function can be shortcuted and sendtimeout is not the best way
|
setTimeout(function(){ pageLoaded(); }, 6000);
|
||||||
}
|
}
|
||||||
xmlHttp.onabort = function(){ if(callback) callback(); }
|
xmlHttp.onabort = function(){ if(callback) callback(); }
|
||||||
xmlHttp.onerror = function(){ if(callback) callback(); }
|
xmlHttp.onerror = function(){ if(callback) callback(); }
|
||||||
@ -230,6 +235,8 @@ core.GridNodes.getNode = function(gridNode, path){ // Return GridNode from RootG
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
gridNode.__isLoading = true;
|
||||||
core.SiteInfos.loadInfos(gridNode.url, { screenshot: true }, function(infos){
|
core.SiteInfos.loadInfos(gridNode.url, { screenshot: true }, function(infos){
|
||||||
if(infos){
|
if(infos){
|
||||||
gridNode.title = infos.title;
|
gridNode.title = infos.title;
|
||||||
@ -239,6 +246,7 @@ core.GridNodes.refreshNode = function(gridNode, callback){ // Refresh content of
|
|||||||
}).then(function(bookmarkItem){}, function(){});
|
}).then(function(bookmarkItem){}, function(){});
|
||||||
core.Settings.save();
|
core.Settings.save();
|
||||||
}
|
}
|
||||||
|
gridNode.__isLoading = false;
|
||||||
if(callback) callback(infos);
|
if(callback) callback(infos);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -270,6 +278,33 @@ core.GridNodes.setNodeIndex = function(gridNode, index, newIndex, callback){ //
|
|||||||
if(callback) callback();
|
if(callback) callback();
|
||||||
browser.runtime.sendMessage({ command: 'gridNodesSynced'}).then(function(){}, function(){});
|
browser.runtime.sendMessage({ command: 'gridNodesSynced'}).then(function(){}, function(){});
|
||||||
}
|
}
|
||||||
|
core.GridNodes.capturePage = function(gridNode, callback){
|
||||||
|
browser.tabs.create({url: gridNode.url, active: false}).then(function(tab){
|
||||||
|
setTimeout(function(){
|
||||||
|
tab.active = true;
|
||||||
|
browser.tabs.update(tab.id, {active: true}).then(function(){
|
||||||
|
browser.tabs.captureVisibleTab().then(function(img){
|
||||||
|
//gridNode.title = tab.title
|
||||||
|
browser.tabs.remove(tab.id);
|
||||||
|
gridNode.image = img;
|
||||||
|
browser.bookmarks.update(gridNode.id, {
|
||||||
|
title: gridNode.title
|
||||||
|
}).then(function(bookmarkItem){}, function(){});
|
||||||
|
core.Settings.save();
|
||||||
|
if(callback) callback();
|
||||||
|
browser.runtime.sendMessage({ command: 'gridNodesSynced'}).then(function(){}, function(){});
|
||||||
|
}, function(){
|
||||||
|
browser.tabs.remove(tab.id);
|
||||||
|
if(callback) callback();
|
||||||
|
});
|
||||||
|
}, function(){
|
||||||
|
if(callback) callback();
|
||||||
|
});
|
||||||
|
}, 4000);
|
||||||
|
}, function(){
|
||||||
|
if(callback) callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Public functions
|
// Public functions
|
||||||
app.refreshNode = core.GridNodes.refreshNode;
|
app.refreshNode = core.GridNodes.refreshNode;
|
||||||
@ -278,3 +313,4 @@ app.createFolder = core.GridNodes.createFolder;
|
|||||||
app.createBookmark = core.GridNodes.createBookmark;
|
app.createBookmark = core.GridNodes.createBookmark;
|
||||||
app.deleteNode = core.GridNodes.delete;
|
app.deleteNode = core.GridNodes.delete;
|
||||||
app.setNodeIndex = core.GridNodes.setNodeIndex;
|
app.setNodeIndex = core.GridNodes.setNodeIndex;
|
||||||
|
app.capturePage = core.GridNodes.capturePage;
|
@ -108,13 +108,19 @@ dial.initMenus = function(){
|
|||||||
dial.ItemMenuCreateFolder = document.createElement('menuitem');
|
dial.ItemMenuCreateFolder = document.createElement('menuitem');
|
||||||
dial.ItemMenuCreateFolder.label = browser.i18n.getMessage("menuAddFolder");
|
dial.ItemMenuCreateFolder.label = browser.i18n.getMessage("menuAddFolder");
|
||||||
dial.ItemMenuCreateFolder.onclick = dial.createFolder;
|
dial.ItemMenuCreateFolder.onclick = dial.createFolder;
|
||||||
|
/*
|
||||||
dial.ItemMenuEdit = document.createElement('menuitem');
|
dial.ItemMenuEdit = document.createElement('menuitem');
|
||||||
dial.ItemMenuEdit.label = 'Edit';
|
dial.ItemMenuEdit.label = 'Edit';
|
||||||
//dial.ItemMenuEdit.onclick = dial.test;
|
//dial.ItemMenuEdit.onclick = dial.test;
|
||||||
|
*/
|
||||||
dial.ItemMenuRefresh = document.createElement('menuitem');
|
dial.ItemMenuRefresh = document.createElement('menuitem');
|
||||||
dial.ItemMenuRefresh.label = 'Refresh';
|
|
||||||
dial.ItemMenuRefresh.label = browser.i18n.getMessage("menuRefreshItem");
|
dial.ItemMenuRefresh.label = browser.i18n.getMessage("menuRefreshItem");
|
||||||
dial.ItemMenuRefresh.onclick = dial.refreshNode;
|
dial.ItemMenuRefresh.onclick = dial.refreshNode;
|
||||||
|
|
||||||
|
dial.ItemMenuCapture = document.createElement('menuitem');
|
||||||
|
dial.ItemMenuCapture.label = 'Capture' // browser.i18n.getMessage("menuRefreshItem");
|
||||||
|
dial.ItemMenuCapture.onclick = dial.capturePage;
|
||||||
|
|
||||||
dial.ItemMenuDelete = document.createElement('menuitem');
|
dial.ItemMenuDelete = document.createElement('menuitem');
|
||||||
dial.ItemMenuDelete.label = browser.i18n.getMessage("menuDeleteItem");
|
dial.ItemMenuDelete.label = browser.i18n.getMessage("menuDeleteItem");
|
||||||
dial.ItemMenuDelete.onclick = dial.deleteNode;
|
dial.ItemMenuDelete.onclick = dial.deleteNode;
|
||||||
@ -123,6 +129,7 @@ dial.initMenus = function(){
|
|||||||
dial.ItemMenu.appendChild(document.createElement('hr'));
|
dial.ItemMenu.appendChild(document.createElement('hr'));
|
||||||
//dial.ItemMenu.appendChild(dial.ItemMenuEdit);
|
//dial.ItemMenu.appendChild(dial.ItemMenuEdit);
|
||||||
dial.ItemMenu.appendChild(dial.ItemMenuRefresh);
|
dial.ItemMenu.appendChild(dial.ItemMenuRefresh);
|
||||||
|
dial.ItemMenu.appendChild(dial.ItemMenuCapture);
|
||||||
dial.ItemMenu.appendChild(dial.ItemMenuDelete);
|
dial.ItemMenu.appendChild(dial.ItemMenuDelete);
|
||||||
dial.Body.appendChild(dial.ItemMenu);
|
dial.Body.appendChild(dial.ItemMenu);
|
||||||
}
|
}
|
||||||
@ -307,4 +314,10 @@ dial.deleteNode = function(){
|
|||||||
if(confirm(browser.i18n.getMessage("deleteItemConfimation", dial._selectedItem.Node.title))){
|
if(confirm(browser.i18n.getMessage("deleteItemConfimation", dial._selectedItem.Node.title))){
|
||||||
app.deleteNode(dial._selectedItem.Node.id);
|
app.deleteNode(dial._selectedItem.Node.id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dial.capturePage = function(){
|
||||||
|
app.capturePage(dial._selectedItem.Node, function(){
|
||||||
|
//
|
||||||
|
})
|
||||||
}
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Quick Dial",
|
"name": "Quick Dial",
|
||||||
"version": "0.0.5",
|
"version": "0.0.1",
|
||||||
|
|
||||||
"description": "__MSG_extensionDescription__",
|
"description": "__MSG_extensionDescription__",
|
||||||
|
|
||||||
@ -18,6 +18,8 @@
|
|||||||
"tabs",
|
"tabs",
|
||||||
"<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
Normal file
BIN
src/src.zip
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user