Include web page save option in toolbar menu on every page
Closes #644 and #775
This commit is contained in:
parent
43e1c5c123
commit
39f2021576
|
@ -150,8 +150,10 @@ var Zotero_Browser = new function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scrapes a page (called when the capture icon is clicked
|
* Saves from current page using translator (called when the capture icon is clicked)
|
||||||
* @return void
|
*
|
||||||
|
* @param {String} [translator]
|
||||||
|
* @param {Event} [event]
|
||||||
*/
|
*/
|
||||||
this.scrapeThisPage = function (translator, event) {
|
this.scrapeThisPage = function (translator, event) {
|
||||||
// Perform translation
|
// Perform translation
|
||||||
|
@ -161,17 +163,19 @@ var Zotero_Browser = new function() {
|
||||||
Zotero_Browser.performTranslation(tab.page.translate);
|
Zotero_Browser.performTranslation(tab.page.translate);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
this.saveAsWebPage(
|
||||||
|
(event && event.shiftKey) ? !Zotero.Prefs.get('automaticSnapshots') : null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Keep in sync with cmd_zotero_newItemFromCurrentPage
|
// Keep in sync with cmd_zotero_newItemFromCurrentPage
|
||||||
//
|
this.saveAsWebPage = function (includeSnapshots) {
|
||||||
// DEBUG: Possible to just trigger command directly with event? Assigning it to the
|
// DEBUG: Possible to just trigger command directly with event? Assigning it to the
|
||||||
// command property of the icon doesn't seem to work, and neither does goDoCommand()
|
// command property of the icon doesn't seem to work, and neither does goDoCommand()
|
||||||
// from chrome://global/content/globalOverlay.js. Getting the command by id and
|
// from chrome://global/content/globalOverlay.js. Getting the command by id and
|
||||||
// running doCommand() works but doesn't pass the event.
|
// running doCommand() works but doesn't pass the event.
|
||||||
ZoteroPane.addItemFromPage(
|
ZoteroPane.addItemFromPage('temporaryPDFHack', includeSnapshots);
|
||||||
'temporaryPDFHack',
|
|
||||||
(event && event.shiftKey) ? !Zotero.Prefs.get('automaticSnapshots') : null
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -495,8 +499,8 @@ var Zotero_Browser = new function() {
|
||||||
while(popup.hasChildNodes()) popup.removeChild(popup.lastChild);
|
while(popup.hasChildNodes()) popup.removeChild(popup.lastChild);
|
||||||
|
|
||||||
var tab = _getTabObject(this.tabbrowser.selectedBrowser);
|
var tab = _getTabObject(this.tabbrowser.selectedBrowser);
|
||||||
|
var captureState = tab.getCaptureState();
|
||||||
if (tab.getCaptureState() == tab.CAPTURE_STATE_TRANSLATABLE) {
|
if (captureState == tab.CAPTURE_STATE_TRANSLATABLE) {
|
||||||
let translators = tab.page.translators;
|
let translators = tab.page.translators;
|
||||||
for (var i=0, n = translators.length; i < n; i++) {
|
for (var i=0, n = translators.length; i < n; i++) {
|
||||||
let translator = translators[i];
|
let translator = translators[i];
|
||||||
|
@ -514,7 +518,30 @@ var Zotero_Browser = new function() {
|
||||||
}, false);
|
}, false);
|
||||||
popup.appendChild(menuitem);
|
popup.appendChild(menuitem);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let webPageIcon = tab.getWebPageCaptureIcon(Zotero.hiDPI);
|
||||||
|
let menuitem = document.createElement("menuitem");
|
||||||
|
menuitem.setAttribute("label", Zotero.getString('ingester.saveToZoteroAsWebPageWithSnapshot'));
|
||||||
|
menuitem.setAttribute("image", webPageIcon);
|
||||||
|
menuitem.setAttribute("class", "menuitem-iconic");
|
||||||
|
menuitem.addEventListener("command", function (event) {
|
||||||
|
Zotero_Browser.saveAsWebPage(true);
|
||||||
|
event.stopPropagation();
|
||||||
|
});
|
||||||
|
popup.appendChild(menuitem);
|
||||||
|
|
||||||
|
menuitem = document.createElement("menuitem");
|
||||||
|
menuitem.setAttribute("label", Zotero.getString('ingester.saveToZoteroAsWebPageWithoutSnapshot'));
|
||||||
|
menuitem.setAttribute("image", webPageIcon);
|
||||||
|
menuitem.setAttribute("class", "menuitem-iconic");
|
||||||
|
menuitem.addEventListener("command", function (event) {
|
||||||
|
Zotero_Browser.saveAsWebPage(false);
|
||||||
|
event.stopPropagation();
|
||||||
|
});
|
||||||
|
popup.appendChild(menuitem);
|
||||||
|
|
||||||
|
if (captureState == tab.CAPTURE_STATE_TRANSLATABLE) {
|
||||||
popup.appendChild(document.createElement("menuseparator"));
|
popup.appendChild(document.createElement("menuseparator"));
|
||||||
|
|
||||||
let menuitem = document.createElement("menuitem");
|
let menuitem = document.createElement("menuitem");
|
||||||
|
@ -538,36 +565,6 @@ var Zotero_Browser = new function() {
|
||||||
Zotero_LocateMenu.locateItem(e, obj.newItems);
|
Zotero_LocateMenu.locateItem(e, obj.newItems);
|
||||||
}), true);
|
}), true);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
let webPageIcon = tab.getCaptureIcon(Zotero.hiDPI);
|
|
||||||
let automaticSnapshots = Zotero.Prefs.get('automaticSnapshots');
|
|
||||||
let snapshotEvent = {
|
|
||||||
shiftKey: !automaticSnapshots
|
|
||||||
};
|
|
||||||
let noSnapshotEvent = {
|
|
||||||
shiftKey: automaticSnapshots
|
|
||||||
};
|
|
||||||
|
|
||||||
let menuitem = document.createElement("menuitem");
|
|
||||||
menuitem.setAttribute("label", "Save to Zotero as Web Page (with snapshot)");
|
|
||||||
menuitem.setAttribute("image", webPageIcon);
|
|
||||||
menuitem.setAttribute("class", "menuitem-iconic");
|
|
||||||
menuitem.addEventListener("command", function (event) {
|
|
||||||
Zotero_Browser.scrapeThisPage(null, snapshotEvent);
|
|
||||||
event.stopPropagation();
|
|
||||||
});
|
|
||||||
popup.appendChild(menuitem);
|
|
||||||
|
|
||||||
menuitem = document.createElement("menuitem");
|
|
||||||
menuitem.setAttribute("label", "Save to Zotero as Web Page (without snapshot)");
|
|
||||||
menuitem.setAttribute("image", webPageIcon);
|
|
||||||
menuitem.setAttribute("class", "menuitem-iconic");
|
|
||||||
menuitem.addEventListener("command", function (event) {
|
|
||||||
Zotero_Browser.scrapeThisPage(null, noSnapshotEvent);
|
|
||||||
event.stopPropagation();
|
|
||||||
});
|
|
||||||
popup.appendChild(menuitem);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -902,12 +899,17 @@ Zotero_Browser.Tab.prototype.getCaptureIcon = function (hiDPI) {
|
||||||
? "chrome://zotero/skin/treesource-collection" + suffix + ".png"
|
? "chrome://zotero/skin/treesource-collection" + suffix + ".png"
|
||||||
: Zotero.ItemTypes.getImageSrc(itemType));
|
: Zotero.ItemTypes.getImageSrc(itemType));
|
||||||
|
|
||||||
// TODO: Show icons for images, PDFs, etc.?
|
|
||||||
default:
|
default:
|
||||||
return "chrome://zotero/skin/treeitem-webpage" + suffix + ".png";
|
return this.getWebPageCaptureIcon(hiDPI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Show icons for images, PDFs, etc.?
|
||||||
|
Zotero_Browser.Tab.prototype.getWebPageCaptureIcon = function (hiDPI) {
|
||||||
|
var suffix = hiDPI ? "@2x" : "";
|
||||||
|
return "chrome://zotero/skin/treeitem-webpage" + suffix + ".png";
|
||||||
|
}
|
||||||
|
|
||||||
Zotero_Browser.Tab.prototype.getCaptureTooltip = function() {
|
Zotero_Browser.Tab.prototype.getCaptureTooltip = function() {
|
||||||
switch (this.getCaptureState()) {
|
switch (this.getCaptureState()) {
|
||||||
case this.CAPTURE_STATE_DISABLED:
|
case this.CAPTURE_STATE_DISABLED:
|
||||||
|
|
|
@ -484,6 +484,8 @@ save.error.cannotAddFilesToCollection = You cannot add files to the currently se
|
||||||
|
|
||||||
ingester.saveToZotero = Save to Zotero
|
ingester.saveToZotero = Save to Zotero
|
||||||
ingester.saveToZoteroUsing = Save to Zotero using "%S"
|
ingester.saveToZoteroUsing = Save to Zotero using "%S"
|
||||||
|
ingester.saveToZoteroAsWebPageWithSnapshot = Save to Zotero as Web Page (with snapshot)
|
||||||
|
ingester.saveToZoteroAsWebPageWithoutSnapshot = Save to Zotero as Web Page (without snapshot)
|
||||||
ingester.scraping = Saving Item…
|
ingester.scraping = Saving Item…
|
||||||
ingester.scrapingTo = Saving to
|
ingester.scrapingTo = Saving to
|
||||||
ingester.scrapeComplete = Item Saved
|
ingester.scrapeComplete = Item Saved
|
||||||
|
|
Loading…
Reference in New Issue
Block a user