1
1
Bifurcation 0

add toolbar icon with popup

has no icons yet; will soon have a keyboard shortcut to open
Cette révision appartient à :
girst 2017-08-19 23:09:49 +02:00
Parent 62bcaabdf0
révision 2977b85e13
5 fichiers modifiés avec 465 ajouts et 381 suppressions

Voir le fichier

@ -1,412 +1,343 @@
openInEnum = {
CURRENT_TAB : 0,
NEW_TAB : 1,
NEW_BGTAB : 2,
NEW_WINDOW : 3
}
var openIn = openInEnum.CURRENT_TAB; var openIn = openInEnum.CURRENT_TAB;
browser.storage.local.get ("openIn").then (function (item) {if (item.openIn) {openIn = item.openIn}}, onError); browser.storage.local.get ("openIn").then (function (item) {
if (item.openIn) {openIn = item.openIn}
/*
Create all the context menu items.
*/
// top level {{{
browser.contextMenus.create({
id: "resurrect-page",
title: browser.i18n.getMessage("contextMenuItemResurrectPage"),
contexts: ["page"]
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link",
title: browser.i18n.getMessage("contextMenuItemResurrectLink"),
contexts: ["link"]
}, onCreated);
browser.contextMenus.create({
id: "resurrect-selection",
title: browser.i18n.getMessage("contextMenuItemResurrectSelection"),
contexts: ["selection"]
}, onCreated);
//}}}
// resurrect page {{{
browser.contextMenus.create({
id: "resurrect-page-google",
title: browser.i18n.getMessage("contextMenuItemResurrectGoogle"),
icons: { 16: "icons/cacheicons/google.png" },
contexts: ["all"],
parentId: "resurrect-page"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-page-googletext",
title: browser.i18n.getMessage("contextMenuItemResurrectGoogleText"),
icons: { 16: "icons/cacheicons/google.png" },
contexts: ["all"],
parentId: "resurrect-page"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-page-archive",
title: browser.i18n.getMessage("contextMenuItemResurrectArchive"),
icons: { 16: "icons/cacheicons/waybackmachine.png" },
contexts: ["all"],
parentId: "resurrect-page"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-page-archiveis",
title: browser.i18n.getMessage("contextMenuItemResurrectArchiveIs"),
icons: { 16: "icons/cacheicons/archiveis.png" },
contexts: ["all"],
parentId: "resurrect-page"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-page-webcitation",
title: browser.i18n.getMessage("contextMenuItemResurrectWebcitation"),
icons: { 16: "icons/cacheicons/webcitation.png" },
contexts: ["all"],
parentId: "resurrect-page"
}, onCreated);
//}}}
// resurrect link {{{
browser.contextMenus.create({
id: "resurrect-link-google",
title: browser.i18n.getMessage("contextMenuItemResurrectGoogle"),
icons: { 16: "icons/cacheicons/google.png" },
contexts: ["all"],
parentId: "resurrect-link"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link-googletext",
title: browser.i18n.getMessage("contextMenuItemResurrectGoogleText"),
icons: { 16: "icons/cacheicons/google.png" },
contexts: ["all"],
parentId: "resurrect-link"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link-archive",
title: browser.i18n.getMessage("contextMenuItemResurrectArchive"),
icons: { 16: "icons/cacheicons/waybackmachine.png" },
contexts: ["all"],
parentId: "resurrect-link"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link-archiveis",
title: browser.i18n.getMessage("contextMenuItemResurrectArchiveIs"),
icons: { 16: "icons/cacheicons/archiveis.png" },
contexts: ["all"],
parentId: "resurrect-link"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link-webcitation",
title: browser.i18n.getMessage("contextMenuItemResurrectWebcitation"),
icons: { 16: "icons/cacheicons/webcitation.png" },
contexts: ["all"],
parentId: "resurrect-link"
}, onCreated);
//}}}
// resurrect selection {{{
browser.contextMenus.create({
id: "resurrect-slct-google",
title: browser.i18n.getMessage("contextMenuItemResurrectGoogle"),
icons: { 16: "icons/cacheicons/google.png" },
contexts: ["all"],
parentId: "resurrect-selection"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-slct-googletext",
title: browser.i18n.getMessage("contextMenuItemResurrectGoogleText"),
icons: { 16: "icons/cacheicons/google.png" },
contexts: ["all"],
parentId: "resurrect-selection"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-slct-archive",
title: browser.i18n.getMessage("contextMenuItemResurrectArchive"),
icons: { 16: "icons/cacheicons/waybackmachine.png" },
contexts: ["all"],
parentId: "resurrect-selection"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-slct-archiveis",
title: browser.i18n.getMessage("contextMenuItemResurrectArchiveIs"),
icons: { 16: "icons/cacheicons/archiveis.png" },
contexts: ["all"],
parentId: "resurrect-selection"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-slct-webcitation",
title: browser.i18n.getMessage("contextMenuItemResurrectWebcitation"),
icons: { 16: "icons/cacheicons/webcitation.png" },
contexts: ["all"],
parentId: "resurrect-selection"
}, onCreated);
//}}}
//config page {{{
browser.contextMenus.create({
id: "separator-1",
type: "separator",
contexts: ["all"],
parentId: "resurrect-page"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-page-current-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigCurrentTab"),
contexts: ["all"],
checked: openIn==openInEnum.CURRENT_TAB,
parentId: "resurrect-page"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-page-new-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewTab"),
contexts: ["all"],
checked: openIn==openInEnum.NEW_TAB,
parentId: "resurrect-page"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-page-new-background-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewBackgroundTab"),
contexts: ["all"],
checked: openIn==openInEnum.NEW_BGTAB,
parentId: "resurrect-page"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-page-new-window",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewWindow"),
contexts: ["all"],
checked: openIn==openInEnum.NEW_WINDOW,
parentId: "resurrect-page"
}, onCreated);
//}}}
//config link {{{
browser.contextMenus.create({
id: "separator-2",
type: "separator",
contexts: ["all"],
parentId: "resurrect-link"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link-current-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigCurrentTab"),
contexts: ["all"],
checked: openIn==openInEnum.CURRENT_TAB,
parentId: "resurrect-link"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link-new-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewTab"),
contexts: ["all"],
checked: openIn==openInEnum.NEW_TAB,
parentId: "resurrect-link"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link-new-background-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewBackgroundTab"),
contexts: ["all"],
checked: openIn==openInEnum.NEW_BGTAB,
parentId: "resurrect-link"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link-new-window",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewWindow"),
contexts: ["all"],
checked: openIn==openInEnum.NEW_WINDOW,
parentId: "resurrect-link"
}, onCreated);
//}}}
//config selection {{{
browser.contextMenus.create({
id: "separator-3",
type: "separator",
contexts: ["all"],
parentId: "resurrect-selection"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-slct-current-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigCurrentTab"),
contexts: ["all"],
checked: openIn==openInEnum.CURRENT_TAB,
parentId: "resurrect-selection"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-slct-new-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewTab"),
contexts: ["all"],
checked: openIn==openInEnum.NEW_TAB,
parentId: "resurrect-selection"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-slct-new-background-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewBackgroundTab"),
contexts: ["all"],
checked: openIn==openInEnum.NEW_BGTAB,
parentId: "resurrect-selection"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-slct-new-window",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewWindow"),
contexts: ["all"],
checked: openIn==openInEnum.NEW_WINDOW,
parentId: "resurrect-selection"
}, onCreated);
//}}}
}, onError);
function onCreated(n) { function onCreated(n) {
if (browser.runtime.lastError) { if (browser.runtime.lastError) {
console.log(`Error: ${browser.runtime.lastError}`); console.log('Error: '+browser.runtime.lastError);
} }
} }
function onRemoved() { }
function onError(error) {
console.log(`Error: ${error}`);
}
/*
Create all the context menu items.
*/
// top level {{{
browser.contextMenus.create({
id: "resurrect-page",
title: browser.i18n.getMessage("contextMenuItemResurrectPage"),
contexts: ["page"]
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link",
title: browser.i18n.getMessage("contextMenuItemResurrectLink"),
contexts: ["link"]
}, onCreated);
browser.contextMenus.create({
id: "resurrect-selection",
title: browser.i18n.getMessage("contextMenuItemResurrectSelection"),
contexts: ["selection"]
}, onCreated);
//}}}
// resurrect page {{{
browser.contextMenus.create({
id: "resurrect-page-google",
title: browser.i18n.getMessage("contextMenuItemResurrectGoogle"),
icons: { 16: "icons/cacheicons/google.png" },
contexts: ["all"],
parentId: "resurrect-page"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-page-googletext",
title: browser.i18n.getMessage("contextMenuItemResurrectGoogleText"),
icons: { 16: "icons/cacheicons/google.png" },
contexts: ["all"],
parentId: "resurrect-page"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-page-archive",
title: browser.i18n.getMessage("contextMenuItemResurrectArchive"),
icons: { 16: "icons/cacheicons/waybackmachine.png" },
contexts: ["all"],
parentId: "resurrect-page"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-page-archiveis",
title: browser.i18n.getMessage("contextMenuItemResurrectArchiveIs"),
icons: { 16: "icons/cacheicons/archiveis.png" },
contexts: ["all"],
parentId: "resurrect-page"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-page-webcitation",
title: browser.i18n.getMessage("contextMenuItemResurrectWebcitation"),
icons: { 16: "icons/cacheicons/webcitation.png" },
contexts: ["all"],
parentId: "resurrect-page"
}, onCreated);
//}}}
// resurrect link {{{
browser.contextMenus.create({
id: "resurrect-link-google",
title: browser.i18n.getMessage("contextMenuItemResurrectGoogle"),
icons: { 16: "icons/cacheicons/google.png" },
contexts: ["all"],
parentId: "resurrect-link"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link-googletext",
title: browser.i18n.getMessage("contextMenuItemResurrectGoogleText"),
icons: { 16: "icons/cacheicons/google.png" },
contexts: ["all"],
parentId: "resurrect-link"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link-archive",
title: browser.i18n.getMessage("contextMenuItemResurrectArchive"),
icons: { 16: "icons/cacheicons/waybackmachine.png" },
contexts: ["all"],
parentId: "resurrect-link"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link-archiveis",
title: browser.i18n.getMessage("contextMenuItemResurrectArchiveIs"),
icons: { 16: "icons/cacheicons/archiveis.png" },
contexts: ["all"],
parentId: "resurrect-link"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link-webcitation",
title: browser.i18n.getMessage("contextMenuItemResurrectWebcitation"),
icons: { 16: "icons/cacheicons/webcitation.png" },
contexts: ["all"],
parentId: "resurrect-link"
}, onCreated);
//}}}
// resurrect selection {{{
browser.contextMenus.create({
id: "resurrect-selection-google",
title: browser.i18n.getMessage("contextMenuItemResurrectGoogle"),
icons: { 16: "icons/cacheicons/google.png" },
contexts: ["all"],
parentId: "resurrect-selection"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-selection-googletext",
title: browser.i18n.getMessage("contextMenuItemResurrectGoogleText"),
icons: { 16: "icons/cacheicons/google.png" },
contexts: ["all"],
parentId: "resurrect-selection"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-selection-archive",
title: browser.i18n.getMessage("contextMenuItemResurrectArchive"),
icons: { 16: "icons/cacheicons/waybackmachine.png" },
contexts: ["all"],
parentId: "resurrect-selection"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-selection-archiveis",
title: browser.i18n.getMessage("contextMenuItemResurrectArchiveIs"),
icons: { 16: "icons/cacheicons/archiveis.png" },
contexts: ["all"],
parentId: "resurrect-selection"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-selection-webcitation",
title: browser.i18n.getMessage("contextMenuItemResurrectWebcitation"),
icons: { 16: "icons/cacheicons/webcitation.png" },
contexts: ["all"],
parentId: "resurrect-selection"
}, onCreated);
//}}}
//config page {{{
browser.contextMenus.create({
id: "separator-1",
type: "separator",
contexts: ["all"],
parentId: "resurrect-page"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-page-current-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigCurrentTab"),
contexts: ["all"],
checked: true,
parentId: "resurrect-page"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-page-new-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewTab"),
contexts: ["all"],
checked: false,
parentId: "resurrect-page"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-page-new-background-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewBackgroundTab"),
contexts: ["all"],
checked: false,
parentId: "resurrect-page"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-page-new-window",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewWindow"),
contexts: ["all"],
checked: false,
parentId: "resurrect-page"
}, onCreated);
//}}}
//config link {{{
browser.contextMenus.create({
id: "separator-2",
type: "separator",
contexts: ["all"],
parentId: "resurrect-link"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link-current-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigCurrentTab"),
contexts: ["all"],
checked: true,
parentId: "resurrect-link"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link-new-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewTab"),
contexts: ["all"],
checked: false,
parentId: "resurrect-link"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link-new-background-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewBackgroundTab"),
contexts: ["all"],
checked: false,
parentId: "resurrect-link"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-link-new-window",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewWindow"),
contexts: ["all"],
checked: false,
parentId: "resurrect-link"
}, onCreated);
//}}}
//config selection {{{
browser.contextMenus.create({
id: "separator-3",
type: "separator",
contexts: ["all"],
parentId: "resurrect-selection"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-selection-current-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigCurrentTab"),
contexts: ["all"],
checked: true,
parentId: "resurrect-selection"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-selection-new-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewTab"),
contexts: ["all"],
checked: false,
parentId: "resurrect-selection"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-selection-new-background-tab",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewBackgroundTab"),
contexts: ["all"],
checked: false,
parentId: "resurrect-selection"
}, onCreated);
browser.contextMenus.create({
id: "resurrect-selection-new-window",
type: "radio",
title: browser.i18n.getMessage("contextMenuItemResurrectConfigNewWindow"),
contexts: ["all"],
checked: false,
parentId: "resurrect-selection"
}, onCreated);
//}}}
browser.contextMenus.onClicked.addListener(function(info, tab) { browser.contextMenus.onClicked.addListener(function(info, tab) {
var gotoUrl=null; var gotoUrl=null;
var rawUrl = info.pageUrl; var rawUrl = info.pageUrl;
switch (info.menuItemId) { switch (info.menuItemId) {
case "resurrect-page-google": case "resurrect-page-google": goToURL (genGoogleURL(info.pageUrl), openIn); break;
gotoUrl='https://www.google.com/search?q=cache:'+encodeURIComponent(info.pageUrl); case "resurrect-link-google": goToURL (genGoogleURL(info.linkUrl), openIn); break;
break; case "resurrect-slct-google": goToURL (genGoogleURL(info.selectionText), openIn); break;
case "resurrect-link-google":
gotoUrl='https://www.google.com/search?q=cache:'+encodeURIComponent(info.linkUrl);
break;
case "resurrect-selection-google":
gotoUrl='https://www.google.com/search?q=cache:'+encodeURIComponent(info.selectionText);
break;
case "resurrect-page-googletext": case "resurrect-page-googletext": goToURL (genGoogleTextURL(info.pageUrl), openIn); break;
gotoUrl='https://www.google.com/search?strip=1&q=cache:'+encodeURIComponent(info.pageUrl); case "resurrect-link-googletext": goToURL (genGoogleTextURL(info.linkUrl), openIn); break;
break; case "resurrect-slct-googletext": goToURL (genGoogleTextURL(info.selectionText), openIn); break;
case "resurrect-link-googletext":
gotoUrl='https://www.google.com/search?strip=1&q=cache:'+encodeURIComponent(info.linkUrl);
break;
case "resurrect-selection-googletext":
gotoUrl='https://www.google.com/search?strip=1&q=cache:'+encodeURIComponent(info.selectionText);
break;
case "resurrect-page-archive": case "resurrect-page-archive": goToURL (genIAURL(info.pageUrl), openIn); break;
var dateStr = (new Date()).toISOString().replace(/-|T|:|\..*/g, ''); case "resurrect-link-archive": goToURL (genIAURL(info.linkUrl), openIn); break;
gotoUrl='https://web.archive.org/web/'+dateStr+'/'+info.pageUrl case "resurrect-slct-archive": goToURL (genIAURL(info.selectionText), openIn); break;
break;
case "resurrect-link-archive":
var dateStr = (new Date()).toISOString().replace(/-|T|:|\..*/g, '');
gotoUrl='https://web.archive.org/web/'+dateStr+'/'+info.linkUrl
break;
case "resurrect-selection-archive":
var dateStr = (new Date()).toISOString().replace(/-|T|:|\..*/g, '');
gotoUrl='https://web.archive.org/web/'+dateStr+'/'+info.selectionText
break;
case "resurrect-page-archiveis": case "resurrect-page-archiveis": goToURL (genArchiveIsURL(info.pageUrl), openIn); break;
gotoUrl='https://archive.is/'+info.pageUrl; case "resurrect-link-archiveis": goToURL (genArchiveIsURL(info.linkUrl), openIn); break;
break; case "resurrect-slct-archiveis": goToURL (genArchiveIsURL(info.selectionText), openIn); break;
case "resurrect-link-archiveis":
gotoUrl='https://archive.is/'+info.linkUrl;
break;
case "resurrect-selection-archiveis":
gotoUrl='https://archive.is/'+info.selectionText;
break;
case "resurrect-page-webcitation": case "resurrect-page-webcitation": goToURL (genWebCiteURL(info.pageUrl), openIn); break;
gotoUrl='http://webcitation.org/query.php?url='+encodeURIComponent(info.pageUrl); case "resurrect-link-webcitation": goToURL (genWebCiteURL(info.linkUrl), openIn); break;
break; case "resurrect-slct-webcitation": goToURL (genWebCiteURL(info.selectionText), openIn); break;
case "resurrect-link-webcitation":
gotoUrl='http://webcitation.org/query.php?url='+encodeURIComponent(info.linkUrl);
break;
case "resurrect-selection-webcitation":
gotoUrl='http://webcitation.org/query.php?url='+encodeURIComponent(info.selectionText);
break;
case "resurrect-page-current-tab": case "resurrect-page-current-tab":
case "resurrect-link-current-tab": case "resurrect-link-current-tab":
case "resurrect-selection-current-tab": case "resurrect-slct-current-tab":
openIn = openInEnum.CURRENT_TAB; setOpenIn (openInEnum.CURRENT_TAB);
browser.storage.local.set({openIn: openIn});
return; return;
case "resurrect-page-new-tab": case "resurrect-page-new-tab":
case "resurrect-link-new-tab": case "resurrect-link-new-tab":
case "resurrect-selection-new-tab": case "resurrect-slct-new-tab":
openIn = openInEnum.NEW_TAB; setOpenIn (openInEnum.NEW_TAB);
browser.storage.local.set({openIn: openIn});
return; return;
case "resurrect-page-new-background-tab": case "resurrect-page-new-background-tab":
case "resurrect-link-new-background-tab": case "resurrect-link-new-background-tab":
case "resurrect-selection-new-background-tab": case "resurrect-slct-new-background-tab":
openIn = openInEnum.NEW_BGTAB; setOpenIn (openInEnum.NEW_BGTAB);
browser.storage.local.set({openIn: openIn});
return; return;
case "resurrect-page-new-window": case "resurrect-page-new-window":
case "resurrect-link-new-window": case "resurrect-link-new-window":
case "resurrect-selection-new-window": case "resurrect-slct-new-window":
openIn = openInEnum.NEW_WINDOW; setOpenIn (openInEnum.NEW_WINDOW);
browser.storage.local.set({openIn: openIn});
return; return;
} }
if (gotoUrl) {
console.log ("would've gone to " + gotoUrl + " opened in " + openIn);
switch (openIn) {
case openInEnum.CURRENT_TAB:
browser.tabs.update({ "url": gotoUrl});
break;
case openInEnum.NEW_TAB:
browser.tabs.create({ "url": gotoUrl});
break;
case openInEnum.NEW_BGTAB:
browser.tabs.create({ "url": gotoUrl, "active":false});
break;
case openInEnum.NEW_WINDOW:
browser.windows.create({ "url": gotoUrl});
break;
}
}
}); });

74
common.js Fichier normal
Voir le fichier

@ -0,0 +1,74 @@
openInEnum = {
CURRENT_TAB : 0,
NEW_TAB : 1,
NEW_BGTAB : 2,
NEW_WINDOW : 3
}
var openIn = openInEnum.CURRENT_TAB;
browser.storage.local.get ("openIn").then (function (item) { if (item.openIn) {openIn = item.openIn} }, onError);
function onError(error) {
console.log('Error: '+error);
}
function genGoogleURL (url) {
return 'https://www.google.com/search?q=cache:'+encodeURIComponent(url);
}
function genGoogleTextURL (url) {
return 'https://www.google.com/search?strip=1&q=cache:'+encodeURIComponent(url);
}
function genIAURL (url) {
var dateStr = (new Date()).toISOString().replace(/-|T|:|\..*/g, '');
return 'https://web.archive.org/web/'+dateStr+'/'+url;
}
function genArchiveIsURL (url) {
return 'https://archive.is/'+url;
}
function genWebCiteURL (url) {
return 'http://webcitation.org/query.php?url='+encodeURIComponent(url);
}
function setOpenIn (where) {
openIn = where;
browser.storage.local.set({openIn: openIn}).then(null, onError);
update_context_radios();
}
function update_context_radios() {
browser.contextMenus.update ("resurrect-page-current-tab" , {checked: openIn==openInEnum.CURRENT_TAB});
browser.contextMenus.update ("resurrect-page-new-tab" , {checked: openIn==openInEnum.NEW_TAB});
browser.contextMenus.update ("resurrect-page-new-background-tab", {checked: openIn==openInEnum.NEW_BGTAB});
browser.contextMenus.update ("resurrect-page-new-window" , {checked: openIn==openInEnum.NEW_WINDOW});
browser.contextMenus.update ("resurrect-link-current-tab" , {checked: openIn==openInEnum.CURRENT_TAB});
browser.contextMenus.update ("resurrect-link-new-tab" , {checked: openIn==openInEnum.NEW_TAB});
browser.contextMenus.update ("resurrect-link-new-background-tab", {checked: openIn==openInEnum.NEW_BGTAB});
browser.contextMenus.update ("resurrect-link-new-window" , {checked: openIn==openInEnum.NEW_WINDOW});
browser.contextMenus.update ("resurrect-slct-current-tab" , {checked: openIn==openInEnum.CURRENT_TAB});
browser.contextMenus.update ("resurrect-slct-new-tab" , {checked: openIn==openInEnum.NEW_TAB});
browser.contextMenus.update ("resurrect-slct-new-background-tab", {checked: openIn==openInEnum.NEW_BGTAB});
browser.contextMenus.update ("resurrect-slct-new-window" , {checked: openIn==openInEnum.NEW_WINDOW});
}
function goToURL (url, where) {
switch (Number(where)) {
case openInEnum.CURRENT_TAB:
browser.tabs.update({ "url": url});
break;
case openInEnum.NEW_TAB:
browser.tabs.create({ "url": url});
break;
case openInEnum.NEW_BGTAB:
browser.tabs.create({ "url": url, "active":false});
break;
case openInEnum.NEW_WINDOW:
browser.windows.create({ "url": url});
break;
}
}

Voir le fichier

@ -13,12 +13,19 @@
}, },
"background": { "background": {
"scripts": ["background.js"] "scripts": ["common.js","background.js"]
},
"browser_action": {
"default_icon": "icons/page-32.png",
"default_title": "__MSG_extensionName__",
"default_popup": "popup.htm"
}, },
"permissions": [ "permissions": [
"storage", "storage",
"contextMenus", "contextMenus",
"tabs",
"activeTab" "activeTab"
], ],

26
popup.htm Fichier normal
Voir le fichier

@ -0,0 +1,26 @@
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font-family: sans-serif;
font-size: small;
}
input[type=button] {
width: 100%;
}
</style>
<form>
<input type="button" id="resurrectWithGoogle"></br>
<input type="button" id="resurrectWithGoogleText"></br>
<input type="button" id="resurrectWithInternetArchive"></br>
<input type="button" id="resurrectWithArchiveIs"></br>
<input type="button" id="resurrectWithWebCite"></br>
<hr>
<input type="radio" name="openIn" value="0" id="current" ><label for="current" id="lc"></label></br>
<input type="radio" name="openIn" value="1" id="newtabfg"><label for="newtabfg" id="ltf"></label></br>
<input type="radio" name="openIn" value="2" id="newtabbg"><label for="newtabbg" id="ltb"></label></br>
<input type="radio" name="openIn" value="3" id="newwin" ><label for="newwin" id="lw"></label></br>
</form>
<script src="common.js"></script>
<script src="popup.js"></script>

46
popup.js Fichier normal
Voir le fichier

@ -0,0 +1,46 @@
document.addEventListener('DOMContentLoaded', function() {
browser.storage.local.get ("openIn").then(function(res) {
switch (Number(res.openIn)) {
case openInEnum.CURRENT_TAB:
document.querySelector("#current").checked = true;
break;
case openInEnum.NEW_TAB:
document.querySelector("#newtabfg").checked = true;
break;
case openInEnum.NEW_BGTAB:
document.querySelector("#newtabbg").checked = true;
break;
case openInEnum.NEW_WINDOW:
document.querySelector("#newwin").checked = true;
break;
default:
document.querySelector("#current").checked = true;
onError("can't read openIn");
}
});
document.querySelector("#lc").innerHTML = browser.i18n.getMessage("contextMenuItemResurrectConfigCurrentTab");
document.querySelector("#ltf").innerHTML = browser.i18n.getMessage("contextMenuItemResurrectConfigNewTab");
document.querySelector("#ltb").innerHTML = browser.i18n.getMessage("contextMenuItemResurrectConfigNewBackgroundTab");
document.querySelector("#lw").innerHTML = browser.i18n.getMessage("contextMenuItemResurrectConfigNewWindow");
document.querySelector("#current").onchange = function(){setOpenIn(document.querySelector('input[name="openIn"]:checked').value)};
document.querySelector("#newtabfg").onchange = function(){setOpenIn(document.querySelector('input[name="openIn"]:checked').value)};
document.querySelector("#newtabbg").onchange = function(){setOpenIn(document.querySelector('input[name="openIn"]:checked').value)};
document.querySelector("#newwin").onchange = function(){setOpenIn(document.querySelector('input[name="openIn"]:checked').value)};
document.querySelector("#resurrectWithGoogle").value = browser.i18n.getMessage("contextMenuItemResurrectGoogle");
document.querySelector("#resurrectWithGoogleText").value = browser.i18n.getMessage("contextMenuItemResurrectGoogleText");
document.querySelector("#resurrectWithInternetArchive").value = browser.i18n.getMessage("contextMenuItemResurrectArchive");
document.querySelector("#resurrectWithArchiveIs").value = browser.i18n.getMessage("contextMenuItemResurrectArchiveIs");
document.querySelector("#resurrectWithWebCite").value = browser.i18n.getMessage("contextMenuItemResurrectWebcitation");
browser.tabs.query({active:true,currentWindow:true}).then(function(tabObj){
pageURL = tabObj[0].url;
document.querySelector("#resurrectWithGoogle").onclick = function(){goToURL (genGoogleURL (pageURL), openIn);window.close()};
document.querySelector("#resurrectWithGoogleText").onclick = function(){goToURL (genGoogleTextURL(pageURL), openIn);window.close()};
document.querySelector("#resurrectWithInternetArchive").onclick = function(){goToURL (genIAURL (pageURL), openIn);window.close()};
document.querySelector("#resurrectWithArchiveIs").onclick = function(){goToURL (genArchiveIsURL (pageURL), openIn);window.close()};
document.querySelector("#resurrectWithWebCite").onclick = function(){goToURL (genWebCiteURL (pageURL), openIn);window.close()};
}, onError);
});