Include web page save option in toolbar menu on every page
Closes #644 and #775
This commit is contained in:
parent
43e1c5c123
commit
39f2021576
2 changed files with 51 additions and 47 deletions
|
@ -150,8 +150,10 @@ var Zotero_Browser = new function() {
|
|||
}
|
||||
|
||||
/**
|
||||
* Scrapes a page (called when the capture icon is clicked
|
||||
* @return void
|
||||
* Saves from current page using translator (called when the capture icon is clicked)
|
||||
*
|
||||
* @param {String} [translator]
|
||||
* @param {Event} [event]
|
||||
*/
|
||||
this.scrapeThisPage = function (translator, event) {
|
||||
// Perform translation
|
||||
|
@ -161,19 +163,21 @@ var Zotero_Browser = new function() {
|
|||
Zotero_Browser.performTranslation(tab.page.translate);
|
||||
}
|
||||
else {
|
||||
// Keep in sync with cmd_zotero_newItemFromCurrentPage
|
||||
//
|
||||
// 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()
|
||||
// from chrome://global/content/globalOverlay.js. Getting the command by id and
|
||||
// running doCommand() works but doesn't pass the event.
|
||||
ZoteroPane.addItemFromPage(
|
||||
'temporaryPDFHack',
|
||||
this.saveAsWebPage(
|
||||
(event && event.shiftKey) ? !Zotero.Prefs.get('automaticSnapshots') : null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Keep in sync with cmd_zotero_newItemFromCurrentPage
|
||||
this.saveAsWebPage = function (includeSnapshots) {
|
||||
// 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()
|
||||
// from chrome://global/content/globalOverlay.js. Getting the command by id and
|
||||
// running doCommand() works but doesn't pass the event.
|
||||
ZoteroPane.addItemFromPage('temporaryPDFHack', includeSnapshots);
|
||||
}
|
||||
|
||||
/*
|
||||
* flags a page for annotation
|
||||
*/
|
||||
|
@ -495,8 +499,8 @@ var Zotero_Browser = new function() {
|
|||
while(popup.hasChildNodes()) popup.removeChild(popup.lastChild);
|
||||
|
||||
var tab = _getTabObject(this.tabbrowser.selectedBrowser);
|
||||
|
||||
if (tab.getCaptureState() == tab.CAPTURE_STATE_TRANSLATABLE) {
|
||||
var captureState = tab.getCaptureState();
|
||||
if (captureState == tab.CAPTURE_STATE_TRANSLATABLE) {
|
||||
let translators = tab.page.translators;
|
||||
for (var i=0, n = translators.length; i < n; i++) {
|
||||
let translator = translators[i];
|
||||
|
@ -514,7 +518,30 @@ var Zotero_Browser = new function() {
|
|||
}, false);
|
||||
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"));
|
||||
|
||||
let menuitem = document.createElement("menuitem");
|
||||
|
@ -535,38 +562,8 @@ var Zotero_Browser = new function() {
|
|||
var locateEngines = Zotero.LocateManager.getVisibleEngines();
|
||||
Zotero_LocateMenu.addLocateEngines(popup, locateEngines,
|
||||
_constructLookupFunction(tab, function(e, obj) {
|
||||
Zotero_LocateMenu.locateItem(e, obj.newItems);
|
||||
}), 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);
|
||||
Zotero_LocateMenu.locateItem(e, obj.newItems);
|
||||
}), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -902,12 +899,17 @@ Zotero_Browser.Tab.prototype.getCaptureIcon = function (hiDPI) {
|
|||
? "chrome://zotero/skin/treesource-collection" + suffix + ".png"
|
||||
: Zotero.ItemTypes.getImageSrc(itemType));
|
||||
|
||||
// TODO: Show icons for images, PDFs, etc.?
|
||||
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() {
|
||||
switch (this.getCaptureState()) {
|
||||
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.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.scrapingTo = Saving to
|
||||
ingester.scrapeComplete = Item Saved
|
||||
|
|
Loading…
Add table
Reference in a new issue