Fixes #257, snapshots not getting the CSS from some web pages
Switched importFromURL() from native Mozilla saveDocument() to WebPageDump code (originally from Scrapbook), which fixes CSS saving problems and other issues -- viewing a WPD snapshot of the New York Times front page causes a crash in the Flash plugin in all Mac browsers, however, unless the Flash security settings are changed to whitelist the Zotero storage directory for accessing the network (but this should be done anyway, since the warning is annoying) Also: - Fix broken items list in Related and Advanced Search windows from r1231 - Fix several _getItemAtRow() errors from r1231 - Adjusted Zotero.Progress API: fade()->startCloseTimer(), kill()->close() - Added forceTitle parameter to importFromURL(), currently unimplemented -- note that order of the last parameter changed - Added progress windows for "Create New Item from Current Page", snapshot, and link actions - Added "Miscellaneous" caption in General pane of preferences - Clarify Mac rich-text warnings - Switched small Export prefpane to generic icon
This commit is contained in:
parent
d9f2a7b466
commit
2875c0d4ce
|
@ -394,9 +394,8 @@ var Zotero_Browser = new function() {
|
|||
var linkText = '<a href="' + url + '" tooltiptext="' + url + '">'
|
||||
+ Zotero.getString('ingester.scrapeErrorDescription.linkText') + '</a>';
|
||||
Zotero_Browser.progress.addDescription(Zotero.getString("ingester.scrapeErrorDescription", linkText));
|
||||
Zotero_Browser.progress.startCloseTimer();
|
||||
}
|
||||
|
||||
Zotero_Browser.progress.fade();
|
||||
}
|
||||
|
||||
|
||||
|
@ -413,6 +412,8 @@ var Zotero_Browser = new function() {
|
|||
if(collection) {
|
||||
collection.addItem(item.getID());
|
||||
}
|
||||
|
||||
Zotero_Browser.progress.startCloseTimer();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -622,8 +623,8 @@ Zotero_Browser.Tab.prototype._selectItems = function(obj, itemList) {
|
|||
var newDialog = window.openDialog("chrome://zotero/content/ingester/selectitems.xul",
|
||||
"_blank","chrome,modal,centerscreen,resizable=yes", io);
|
||||
|
||||
if(!io.dataOut) { // user selected no items, so kill the progress indicatior
|
||||
Zotero_Browser.progress.kill();
|
||||
if(!io.dataOut) { // user selected no items, so close the progress indicatior
|
||||
Zotero_Browser.progress.close();
|
||||
}
|
||||
|
||||
return io.dataOut;
|
||||
|
|
|
@ -1504,6 +1504,13 @@ var ZoteroPane = new function()
|
|||
|
||||
|
||||
function addItemFromPage() {
|
||||
var progressWin = new Zotero.ProgressWindow();
|
||||
progressWin.changeHeadline(Zotero.getString('ingester.scraping'));
|
||||
var icon = 'chrome://zotero/skin/treeitem-webpage.png';
|
||||
progressWin.addLines(window.content.document.title, icon)
|
||||
progressWin.show();
|
||||
progressWin.startCloseTimer();
|
||||
|
||||
var data = {
|
||||
title: window.content.document.title,
|
||||
url: window.content.document.location.href,
|
||||
|
@ -1515,27 +1522,55 @@ var ZoteroPane = new function()
|
|||
// Automatically save snapshot if pref set
|
||||
if (item.getID() && Zotero.Prefs.get('automaticSnapshots'))
|
||||
{
|
||||
this.addAttachmentFromPage(false, item.getID(), true);
|
||||
var f = function() {
|
||||
// We set |noParent|, since child items don't belong to collections
|
||||
ZoteroPane.addAttachmentFromPage(false, item.getID(), true);
|
||||
}
|
||||
// Give progress window time to appear
|
||||
setTimeout(f, 300);
|
||||
}
|
||||
|
||||
return item.getID();
|
||||
}
|
||||
|
||||
|
||||
function addAttachmentFromPage(link, id, noParent)
|
||||
/*
|
||||
* Create an attachment from the current page
|
||||
*
|
||||
* |link| -- create web link instead of snapshot
|
||||
* |itemID| -- itemID of parent item
|
||||
* |noParent| -- don't add to current collection
|
||||
*/
|
||||
function addAttachmentFromPage(link, itemID, noParent)
|
||||
{
|
||||
if (this.itemsView && this.itemsView._itemGroup.isCollection() && !noParent) {
|
||||
var parentCollectionID = this.itemsView._itemGroup.ref.getID();
|
||||
if (!noParent) {
|
||||
var progressWin = new Zotero.ProgressWindow();
|
||||
progressWin.changeHeadline(Zotero.getString('save.' + (link ? 'link' : 'attachment')));
|
||||
var type = link ? 'web-link' : 'snapshot';
|
||||
var icon = 'chrome://zotero/skin/treeitem-attachment-' + type + '.png';
|
||||
progressWin.addLines(window.content.document.title, icon)
|
||||
progressWin.show();
|
||||
progressWin.startCloseTimer();
|
||||
|
||||
Zotero.debug('here');
|
||||
if (this.itemsView && this.itemsView._itemGroup.isCollection()) {
|
||||
Zotero.debug('here2');
|
||||
var parentCollectionID = this.itemsView._itemGroup.ref.getID();
|
||||
Zotero.debug(parentCollectionID);
|
||||
}
|
||||
}
|
||||
|
||||
if(link)
|
||||
{
|
||||
Zotero.Attachments.linkFromDocument(window.content.document, id, parentCollectionID);
|
||||
}
|
||||
else
|
||||
{
|
||||
Zotero.Attachments.importFromDocument(window.content.document, id, false, parentCollectionID);
|
||||
var f = function() {
|
||||
Zotero.debug(parentCollectionID);
|
||||
if (link) {
|
||||
Zotero.Attachments.linkFromDocument(window.content.document, itemID, false, parentCollectionID);
|
||||
}
|
||||
else {
|
||||
Zotero.Attachments.importFromDocument(window.content.document, itemID, false, false, parentCollectionID);
|
||||
}
|
||||
}
|
||||
// Give progress window time to appear
|
||||
setTimeout(f, 100);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -55,10 +55,10 @@
|
|||
oncommand="var itemID = ZoteroPane.addItemFromPage(); ZoteroPane.newNote(false, itemID, window.content.getSelection().toString())"/>
|
||||
<menuitem id="zotero-context-save-link-as-snapshot" class="menu-iconic"
|
||||
label="&zotero.contextMenu.saveLinkAsSnapshot;"
|
||||
oncommand="Zotero.Attachments.importFromURL(window.gContextMenu.linkURL, false, false, ZoteroPane.getSelectedCollection(true))"/>
|
||||
oncommand="Zotero.Attachments.importFromURL(window.gContextMenu.linkURL, false, false, false, ZoteroPane.getSelectedCollection(true))"/>
|
||||
<menuitem id="zotero-context-save-image-as-snapshot" class="menu-iconic"
|
||||
label="&zotero.contextMenu.saveImageAsSnapshot;"
|
||||
oncommand="Zotero.Attachments.importFromURL(window.gContextMenu.onImage ? window.gContextMenu.imageURL : window.gContextMenu.bgImageURL, false, false, ZoteroPane.getSelectedCollection(true))"/>
|
||||
oncommand="Zotero.Attachments.importFromURL(window.gContextMenu.onImage ? window.gContextMenu.imageURL : window.gContextMenu.bgImageURL, false, false, false, ZoteroPane.getSelectedCollection(true))"/>
|
||||
</popup>
|
||||
|
||||
<vbox id="appcontent">
|
||||
|
|
|
@ -108,6 +108,8 @@ To add a new preference:
|
|||
</groupbox>
|
||||
|
||||
<groupbox>
|
||||
<caption label="&zotero.preferences.miscellaneous;"/>
|
||||
|
||||
<hbox align="center">
|
||||
<checkbox label="&zotero.preferences.autoUpdate;" preference="pref-automaticScraperUpdates"/>
|
||||
<button id="updateButton" style="margin-top:0" label="&zotero.preferences.updateNow;" oncommand="Zotero.Schema.updateScrapersRemote(true)"/>
|
||||
|
|
790
chrome/content/zotero/webpagedump/common.js
Normal file
790
chrome/content/zotero/webpagedump/common.js
Normal file
|
@ -0,0 +1,790 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is ScrapBook.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Gomita.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Bernhard Pollak <pollak@dbai.tuwien.ac.at> (WebPageDump Fork)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
// "WebPageDump" Firefox Extension
|
||||
// --------------------------------------------------------------------------------
|
||||
// - File: "common.js" -
|
||||
// - Description:
|
||||
// provides common functions (file, preferences, windows, error,...)
|
||||
//
|
||||
// --------------------------------------------------------------------------------
|
||||
|
||||
|
||||
var gBrowserWindow = null;
|
||||
var gExceptLocation = "about:blank";
|
||||
var gCallback = "";
|
||||
var gTimeOutID = 0;
|
||||
var gTimedOut = false;
|
||||
var gWaitForPaint = false;
|
||||
|
||||
var MODE_SIMULATE = false;
|
||||
var WPD_DEFAULTWIDTH=1024;
|
||||
var WPD_DEFAULTHEIGHT=768;
|
||||
|
||||
var WPD_MAXUIERRORCOUNT=8;
|
||||
|
||||
|
||||
/*function wpdGetTopBrowserWindow()
|
||||
{
|
||||
var winMed = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||
.getService(Components.interfaces.nsIWindowMediator);
|
||||
var winList = winMed.getZOrderDOMWindowEnumerator("navigator:browser", true);
|
||||
if (!winList.hasMoreElements())
|
||||
return top.getBrowser().contentWindow; // fallback
|
||||
|
||||
return winList.getNext().getBrowser().contentWindow;
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
/* [14:55:15] paolinho: var browserWin = windowMediator.getMostRecentWindow("navigator:browser");
|
||||
const mainTabBox = browserWin.getBrowser().mTabBox;
|
||||
const topWindow = browserWin.getBrowser().browsers[mainTabBox.selectedIndex].contentWindow;
|
||||
[14:55:50] … var windowMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
|
||||
*/
|
||||
|
||||
function wpdGetTopBrowserWindow()
|
||||
{
|
||||
var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
|
||||
var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
|
||||
var topWindowOfType = windowManagerInterface.getMostRecentWindow( "navigator:browser" );
|
||||
|
||||
if (topWindowOfType) {
|
||||
return topWindowOfType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
function wpdWindowLoaded()
|
||||
{
|
||||
try {
|
||||
// this will be called multiple times if the page contains more than one document (frames, flash,...)
|
||||
//var browser=this.document.getElementById("content");
|
||||
dump("[wpdWindowLoaded] ... \n");
|
||||
var browser = this.top.getBrowser();
|
||||
// each time we have to check if the page is fully loaded...
|
||||
if (!(browser.webProgress.isLoadingDocument || browser.contentDocument.location == gExceptLocation)) {
|
||||
dump("[wpdWindowLoaded] window finally loaded\n");
|
||||
gBrowserWindow.clearTimeout(gTimeOutID);
|
||||
gBrowserWindow.removeEventListener("load",wpdWindowLoaded,true);
|
||||
//dump("[wpdWindowLoaded] calling "+gCallback+"\n");
|
||||
if (gWaitForPaint) {
|
||||
wpdCommon.sizeWindow(WPD_DEFAULTWIDTH-1,WPD_DEFAULTHEIGHT); // this is for the strange empty lines bug
|
||||
wpdCommon.sizeWindow(WPD_DEFAULTWIDTH,WPD_DEFAULTHEIGHT);
|
||||
}
|
||||
var w=0;
|
||||
if (gWaitForPaint) w=5000; // wait for painting
|
||||
gBrowserWindow.setTimeout(gCallback, w);
|
||||
}
|
||||
} catch (ex) {
|
||||
dump("[wpdWindowLoaded] EXCEPTION: "+ex+"\n");
|
||||
}
|
||||
}
|
||||
|
||||
function wpdTimeOut()
|
||||
{
|
||||
dump("[wpdTimeOut] timeout triggered!\n");
|
||||
gTimedOut=true;
|
||||
gBrowserWindow.clearTimeout(gTimeOutID);
|
||||
gBrowserWindow.removeEventListener("load",wpdWindowLoaded,true);
|
||||
gBrowserWindow.setTimeout(gCallback, 0);
|
||||
}
|
||||
|
||||
function wpdIsTimedOut()
|
||||
{
|
||||
return gTimedOut;
|
||||
}
|
||||
|
||||
function wpdLoadURL(aURI,aCallback)
|
||||
{
|
||||
try {
|
||||
gTimedOut=false;
|
||||
dump("\n[wpdLoadURL] aURI: "+aURI+"\n");
|
||||
if (aURI=="") return;
|
||||
gBrowserWindow = wpdGetTopBrowserWindow();
|
||||
gBrowserWindow.loadURI(aURI);
|
||||
gCallback = aCallback;
|
||||
// 30 seconds maximum for loading the page
|
||||
gTimeOutID=gBrowserWindow.setTimeout(wpdTimeOut, 60000);
|
||||
gBrowserWindow.addEventListener("load",wpdWindowLoaded, true);
|
||||
} catch (ex) {
|
||||
dump("[wpdLoadURL] EXCEPTION: "+ex+"\n");
|
||||
}
|
||||
}
|
||||
|
||||
var wpdCommon = {
|
||||
|
||||
errList : "",
|
||||
errCount : 0,
|
||||
downloading : false,
|
||||
downloaded : false,
|
||||
|
||||
allowed_entities:
|
||||
""&'<> ¡¢£¤¥¦"+
|
||||
"§¨©ª«¬­®¯°±"+
|
||||
"²³´µ¶·¸¹º»"+
|
||||
"¼½¾¿ÀÁÂÃÄ"+
|
||||
"ÅÆÇÈÉÊËÌÍ"+
|
||||
"ÎÏÐÑÒÓÔÕÖ"+
|
||||
"×ØÙÚÛÜÝÞß"+
|
||||
"àáâãäåæçè"+
|
||||
"éêëìíîïðñò"+
|
||||
"óôõö÷øùúûü"+
|
||||
"ýþÿŒœŠšŸƒˆ"+
|
||||
"˜ΑΒΓΔΕΖΗΘΙΚ"+
|
||||
"ΛΜΝΞΟΠΡΣΤΥΦΧΨ"+
|
||||
"Ωαβγδεζηθικ"+
|
||||
"λμνξοπρςστυφ"+
|
||||
"χψωϑϒφϖ   ‌"+
|
||||
"‍‎‏–—‘’‚“”„"+
|
||||
"†‡•…‰′″‹›"+
|
||||
"‾⁄€ℑ℘ℜ™ℵ←↑"+
|
||||
"→↓↔↵⇐⇑⇒⇓⇔∀"+
|
||||
"∂∃∅∇∈∉∋∏∑−∗√"+
|
||||
"∝∞∠∨∩∪∫∴∼≅≈≠≡"+
|
||||
"≤≥⊂⊃⊄⊆⊇⊕⊗⊥⋅⌈"+
|
||||
"⌉⌊⌋⟨⟩◊♠♣♥♦",
|
||||
|
||||
|
||||
|
||||
trim : function (aString) {
|
||||
try {
|
||||
return (aString.replace(/\s+$/,"").replace(/^\s+/,""));
|
||||
} catch(ex) {
|
||||
return aString;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// checks the CRLFs at the beginning - if there are CRLFs present
|
||||
// one additional CRLF will be added at the beginning
|
||||
checkCRLF : function (aNode)
|
||||
{
|
||||
try {
|
||||
var before=false;
|
||||
var after=false;
|
||||
if (aNode.parentNode.firstChild==aNode) before=true;
|
||||
if (!before && !after) {
|
||||
throw new Error("return");
|
||||
}
|
||||
// why <BR>? Because the <BR> Tag ist not present in text DOM nodes...
|
||||
var aString=aNode.nodeValue;
|
||||
if (aString.search(/\n/)==-1) throw new Error("return");
|
||||
aString=(aString.replace(/\r\n/g,"<br>").replace(/\n/g,"<br>"));
|
||||
var a=aString.split("<br>");
|
||||
var s=0;
|
||||
var e=0;
|
||||
|
||||
|
||||
if (before) {
|
||||
for (var i=0;i<a.length;i++) {
|
||||
if (this.trim(a[i])!="") {
|
||||
break;
|
||||
} else {
|
||||
s++;
|
||||
break; //we only need to now if there are any
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
aString=a.join("\r\n");
|
||||
if (s>0) aString="\r\n"+aString;
|
||||
return aString;
|
||||
|
||||
} catch (ex) {
|
||||
return aNode.nodeValue;
|
||||
}
|
||||
},
|
||||
|
||||
unicodeToEntity : function (text,charset)
|
||||
{
|
||||
|
||||
function convertEntity(letter) {
|
||||
try {
|
||||
var l = gEntityConverter.ConvertToEntity(letter,entityVersion);
|
||||
// is the entity allowed?
|
||||
if (entities.indexOf(l)>=0) {
|
||||
return l;
|
||||
} else if ( (l!=letter) ) {
|
||||
return "&#"+letter.charCodeAt(0)+";";
|
||||
}
|
||||
} catch (ex) {
|
||||
}
|
||||
// now we check if the letter is valid inside the destination charset
|
||||
// (if the result is a ? it is not valid - except letter=?)
|
||||
try {
|
||||
var s=gUnicodeConverter.ConvertFromUnicode(letter);
|
||||
if ( (charset!="UTF-8") && (s=="?") ) {
|
||||
return "&#"+letter.charCodeAt(0)+";";
|
||||
}
|
||||
} catch (ex) {
|
||||
}
|
||||
return letter;
|
||||
}
|
||||
|
||||
if (!gUnicodeConverter) {
|
||||
try {
|
||||
var gUnicodeConverter = Components.classes['@mozilla.org/intl/scriptableunicodeconverter'].getService(Components.interfaces.nsIScriptableUnicodeConverter);
|
||||
gUnicodeConverter.charset = charset;
|
||||
} catch(ex) {
|
||||
dump ("gUnicodeConverter EXCEPTION:"+ex+"\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (!gEntityConverter) {
|
||||
try {
|
||||
var gEntityConverter = Components.classes["@mozilla.org/intl/entityconverter;1"].createInstance(Components.interfaces.nsIEntityConverter);
|
||||
} catch(e) {
|
||||
dump ("gEntityConverter EXCEPTION:"+ex+"\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Firefox - Source Code Snippet:
|
||||
// const unsigned long entityNone = 0;
|
||||
// const unsigned long html40Latin1 = 1;
|
||||
// const unsigned long html40Symbols = 2;
|
||||
// const unsigned long html40Special = 4; // excludes ", &, <, >
|
||||
// const unsigned long transliterate = 8;
|
||||
// const unsigned long mathml20 = 16;
|
||||
// const unsigned long html32 = html40Latin1;
|
||||
// const unsigned long html40 = html40Latin1+html40Symbols+html40Special;
|
||||
// const unsigned long entityW3C = html40+mathml20;
|
||||
const entityVersion = Components.interfaces.nsIEntityConverter.html40;
|
||||
// convert to entities (
|
||||
// replace other chars > 0x7f via nsIEntityConverter/convertEntity
|
||||
var entities = this.allowed_entities;
|
||||
text = text.replace(/[^\0-\u007f]/g, convertEntity);
|
||||
return text;
|
||||
},
|
||||
|
||||
|
||||
playSound : function()
|
||||
{
|
||||
try {
|
||||
var sound = Components.classes["@mozilla.org/sound;1"].createInstance(Components.interfaces.nsISound);
|
||||
sound.playSystemSound("ringin.wav");
|
||||
} catch(ex) {
|
||||
}
|
||||
},
|
||||
|
||||
// return the current focused window
|
||||
getFocusedWindow : function()
|
||||
{
|
||||
var win = document.commandDispatcher.focusedWindow;
|
||||
if ( !win || win == window || win instanceof Components.interfaces.nsIDOMChromeWindow ) win = window._content;
|
||||
return win;
|
||||
},
|
||||
|
||||
sizeWindow : function(w,h)
|
||||
{
|
||||
try {
|
||||
var window=this.getFocusedWindow();
|
||||
window.moveTo(0,0);
|
||||
if ((w==0) || (w>screen.availWidth)) w=screen.availWidth;
|
||||
if ((h==0) || (w>screen.availHeight)) h=screen.availHeight;
|
||||
window.resizeTo(w,h);
|
||||
window.focus();
|
||||
} catch(ex) {
|
||||
}
|
||||
},
|
||||
|
||||
// add a line to the error list (displays a maximum of 15 errors)
|
||||
addError : function(aError)
|
||||
{
|
||||
dump('ERROR: '+aError+"\n");
|
||||
if (this.errCount<WPD_MAXUIERRORCOUNT) {
|
||||
if (this.errList.indexOf(aError)>-1) return; // is the same
|
||||
this.errList = this.errList+aError+"\n";
|
||||
} else if (this.errCount==WPD_MAXUIERRORCOUNT) {
|
||||
this.errList = this.errList+'...';
|
||||
}
|
||||
this.errCount++;
|
||||
},
|
||||
|
||||
saveWebPage : function(aDestFile) {
|
||||
dump("[saveWebPage] "+aDestFile+"\n");
|
||||
var nsIWBP = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Components.interfaces.nsIWebBrowserPersist);
|
||||
var doc = window.content.document;
|
||||
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
|
||||
file.initWithPath(aDestFile);
|
||||
var dataPath = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
|
||||
dataPath.initWithPath(this.getFilePath(aDestFile));
|
||||
nsIWBP.saveDocument(doc, file, dataPath, null, 0, 0);
|
||||
},
|
||||
|
||||
// returns num as string of length i filled up with 0s
|
||||
addLeftZeros : function(num,i)
|
||||
{
|
||||
var s=""+num;
|
||||
var r="";
|
||||
for (var f=0;f<i-s.length;f++) r=r+"0";
|
||||
return r+s;
|
||||
},
|
||||
|
||||
// split the filename in filename and extension
|
||||
splitFileName : function(aFileName)
|
||||
{
|
||||
var pos = aFileName.lastIndexOf(".");
|
||||
var ret = [];
|
||||
if ( pos != -1 ) {
|
||||
ret[0] = aFileName.substring(0, pos);
|
||||
ret[1] = aFileName.substring(pos + 1, aFileName.length);
|
||||
} else {
|
||||
ret[0] = aFileName;
|
||||
ret[1] = "";
|
||||
}
|
||||
return ret;
|
||||
},
|
||||
|
||||
// replace illegal characters
|
||||
getValidFileName : function(aFileName)
|
||||
{
|
||||
aFileName = aFileName.replace(/[\"\?!~`]+/g, "");
|
||||
aFileName = aFileName.replace(/[\*\&]+/g, "+");
|
||||
aFileName = aFileName.replace(/[\\\/\|\:;]+/g, "-");
|
||||
aFileName = aFileName.replace(/[\<]+/g, "(");
|
||||
aFileName = aFileName.replace(/[\>]+/g, ")");
|
||||
aFileName = aFileName.replace(/[\s]+/g, "_");
|
||||
aFileName = aFileName.replace(/[%]+/g, "@");
|
||||
return aFileName;
|
||||
},
|
||||
|
||||
getURL : function()
|
||||
{
|
||||
return top.window._content.document.location.href;
|
||||
},
|
||||
|
||||
// remove get variables from an URL
|
||||
removeGETFromURL : function(aURL)
|
||||
{
|
||||
var pos;
|
||||
aURL = ( (pos = aURL.indexOf("?")) != -1 ) ? aURL.substring(0, pos) : aURL;
|
||||
aURL = ( (pos = aURL.indexOf("#")) != -1 ) ? aURL.substring(0, pos) : aURL;
|
||||
return aURL;
|
||||
},
|
||||
|
||||
// extract filename from URL
|
||||
getFileName : function(aURL)
|
||||
{
|
||||
var pos;
|
||||
aURL = this.removeGETFromURL(aURL);
|
||||
aURL = ( (pos = aURL.lastIndexOf("/")) != -1 ) ? aURL.substring(++pos) : aURL;
|
||||
return aURL;
|
||||
},
|
||||
|
||||
filePathToURI: function(filePath)
|
||||
{
|
||||
var obj_File = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile);
|
||||
obj_File.initWithPath(filePath);
|
||||
var obj_FPH = Components.classes["@mozilla.org/network/protocol;1?name=file"].getService(Components.interfaces.nsIFileProtocolHandler);
|
||||
return obj_FPH.getURLSpecFromFile(obj_File);
|
||||
},
|
||||
|
||||
URLToFilePath: function(aURL)
|
||||
{
|
||||
var obj_FPH = Components.classes["@mozilla.org/network/protocol;1?name=file"].getService(Components.interfaces.nsIFileProtocolHandler);
|
||||
try {
|
||||
return obj_FPH.getFileFromURLSpec(aURL).path;
|
||||
} catch(ex) {
|
||||
return aURL;
|
||||
}
|
||||
},
|
||||
|
||||
// right part of filepath/filename
|
||||
getFileLeafName: function(filePath)
|
||||
{
|
||||
var obj_File = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile);
|
||||
obj_File.initWithPath(filePath);
|
||||
return obj_File.leafName;
|
||||
},
|
||||
|
||||
getFilePath: function(filePath)
|
||||
{
|
||||
var obj_File = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile);
|
||||
obj_File.initWithPath(filePath);
|
||||
var pos; // Added by Dan S. for Zotero
|
||||
return ( (pos = filePath.lastIndexOf(obj_File.leafName)) != -1 ) ? filePath.substring(0,pos) : filePath;
|
||||
},
|
||||
|
||||
appendFilePath: function(filePath,appendPath)
|
||||
{
|
||||
var obj_File = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile);
|
||||
obj_File.initWithPath(filePath);
|
||||
obj_File.appendRelativePath(appendPath);
|
||||
return obj_File.path;
|
||||
},
|
||||
|
||||
pathExists: function(filePath)
|
||||
{
|
||||
var obj_File = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile);
|
||||
try {
|
||||
obj_File.initWithPath(filePath);
|
||||
return obj_File.exists();
|
||||
} catch(ex) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
// add the HTML Tag Stuff to aNode and embedd the aNode.innerHTML between the tags
|
||||
nodeToHTMLString: function(aNode)
|
||||
{
|
||||
if (aNode==null) return "";
|
||||
var tag = "<" + aNode.nodeName.toLowerCase();
|
||||
for ( var i=0; i<aNode.attributes.length; i++ )
|
||||
tag += ' ' + aNode.attributes[i].name + '="' + aNode.attributes[i].value + '"';
|
||||
tag += ">\n";
|
||||
return tag + aNode.innerHTML + "</" + aNode.nodeName.toLowerCase() + ">\n";
|
||||
},
|
||||
|
||||
ConvertFromUnicode16 : function(aString,charset)
|
||||
{
|
||||
if ( !aString ) return "";
|
||||
try {
|
||||
var UNICODE = Components.classes['@mozilla.org/intl/scriptableunicodeconverter'].getService(Components.interfaces.nsIScriptableUnicodeConverter);
|
||||
UNICODE.charset = charset;
|
||||
aString = UNICODE.ConvertFromUnicode(aString);
|
||||
aString = aString + UNICODE.Finish();
|
||||
} catch(ex) {
|
||||
//this.addError("[wpdCommon.convertStringToCharset]:\n -> charset: "+charset+"\n -> "+ex);
|
||||
}
|
||||
return aString;
|
||||
},
|
||||
|
||||
ConvertToUnicode16 : function(aString,charset)
|
||||
{
|
||||
if ( !aString ) return "";
|
||||
try {
|
||||
var UNICODE = Components.classes['@mozilla.org/intl/scriptableunicodeconverter'].getService(Components.interfaces.nsIScriptableUnicodeConverter);
|
||||
UNICODE.charset = charset;
|
||||
aString = UNICODE.ConvertToUnicode(aString);
|
||||
} catch(ex) {
|
||||
//this.addError("[wpdCommon.convertStringToCharset]:\n -> charset: "+charset+"\n -> "+ex);
|
||||
}
|
||||
return aString;
|
||||
},
|
||||
|
||||
// convert the doctype to an HTML doctype String
|
||||
doctypeToHTMLString : function(aDoctype)
|
||||
{
|
||||
if ( !aDoctype ) return "";
|
||||
var ret = "<!DOCTYPE " + aDoctype.name;
|
||||
if ( aDoctype.publicId ) ret += ' PUBLIC "' + aDoctype.publicId + '"';
|
||||
if ( aDoctype.systemId ) ret += ' "' + aDoctype.systemId + '"';
|
||||
ret += ">\n";
|
||||
return ret;
|
||||
},
|
||||
|
||||
addCommentTag : function(targetNode, aComment)
|
||||
{
|
||||
targetNode.appendChild(document.createTextNode("\n"));
|
||||
targetNode.appendChild(document.createComment(aComment));
|
||||
targetNode.appendChild(document.createTextNode("\n"));
|
||||
},
|
||||
|
||||
|
||||
removeNodeFromParent : function(aNode)
|
||||
{
|
||||
var newNode = document.createTextNode("");
|
||||
aNode.parentNode.replaceChild(newNode, aNode);
|
||||
aNode = newNode;
|
||||
return aNode;
|
||||
},
|
||||
|
||||
// convert URL String to Object
|
||||
// for easier URL handling
|
||||
convertURLToObject : function(aURLString)
|
||||
{
|
||||
var aURL = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURL);
|
||||
aURL.spec = aURLString;
|
||||
return aURL;
|
||||
},
|
||||
|
||||
// resolves the relative URL (aRelURL) with the base URL (aBaseURL)
|
||||
resolveURL : function(aBaseURL, aRelURL)
|
||||
{
|
||||
try {
|
||||
var aBaseURLObj = this.convertURLToObject(aBaseURL);
|
||||
return aBaseURLObj.resolve(aRelURL);
|
||||
} catch(ex) {
|
||||
this.addError("[wpdCommon.resolveURL]:\n -> aBaseURL: "+aBaseURL+"\n -> aRelURL: "+aRelURL+"\n -> "+ex);
|
||||
}
|
||||
return "";
|
||||
},
|
||||
|
||||
getHostName : function(aURL)
|
||||
{
|
||||
try {
|
||||
var aURLObj = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURI);
|
||||
aURLObj.spec = aURL
|
||||
return aURLObj.asciiHost;
|
||||
} catch(ex) {
|
||||
this.addError("[wpdCommon.getHostName]:\n -> aURL: "+aURL+"\n -> "+ex);
|
||||
}
|
||||
return "";
|
||||
},
|
||||
|
||||
convertUrlToASCII : function(aURL)
|
||||
{
|
||||
try {
|
||||
var aURLObj = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURI);
|
||||
aURLObj.spec = aURL
|
||||
return aURLObj.asciiSpec;
|
||||
} catch(ex) {
|
||||
this.addError("[wpdCommon.getHostName]:\n -> aURL: "+aURL+"\n -> "+ex);
|
||||
}
|
||||
return "";
|
||||
},
|
||||
|
||||
createDir : function(str_Dir)
|
||||
{
|
||||
var obj_File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
|
||||
obj_File.initWithPath(str_Dir);
|
||||
if (!obj_File.exists())
|
||||
obj_File.create(obj_File.DIRECTORY_TYPE, 0700);
|
||||
},
|
||||
|
||||
readDir : function(str_Dir)
|
||||
{
|
||||
var obj_File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
|
||||
obj_File.initWithPath(str_Dir);
|
||||
if (obj_File.exists()) return obj_File.directoryEntries;
|
||||
return [];
|
||||
},
|
||||
|
||||
fileSize : function(str_Filename)
|
||||
{
|
||||
var obj_File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
|
||||
obj_File.initWithPath(str_Filename);
|
||||
return obj_File.fileSize;
|
||||
},
|
||||
|
||||
// read the file (str_Filename) to a String Buffer (str_Buffer)
|
||||
readFile : function(str_Filename,removeComments,text)
|
||||
{
|
||||
try{
|
||||
var obj_File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
|
||||
obj_File.initWithPath(str_Filename);
|
||||
if (!obj_File.exists()) {
|
||||
this.addError("[wpdCommon.readFile]:\n -> str_Filename: "+str_Filename+"\n -> file not found!");
|
||||
return "";
|
||||
}
|
||||
|
||||
var obj_Transport = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
|
||||
|
||||
obj_Transport.init( obj_File, 0x01 , 004, 0 );
|
||||
|
||||
var sis = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance( Components.interfaces.nsIScriptableInputStream );
|
||||
sis.init( obj_Transport );
|
||||
var output = sis.read( sis.available() );
|
||||
if (text) output = output.replace(/\r/g,"");
|
||||
if (text && removeComments) {
|
||||
output = output.replace(/^\/\/.*/g,"");
|
||||
output = output.replace(/\n\/\/.*/g,"");
|
||||
output = output.replace(/\n\n+/g,"\n");
|
||||
}
|
||||
if (text) output = output.split(/\n/g);
|
||||
return output;
|
||||
} catch (ex) {
|
||||
this.addError("[wpdCommon.readFile]:\n -> str_Filename: "+str_Filename+"\n -> "+ex);
|
||||
}
|
||||
return "";
|
||||
},
|
||||
|
||||
// write the String Buffer (str_Buffer) to a file (str_Filename)
|
||||
writeFile : function(str_Buffer,str_Filename)
|
||||
{
|
||||
if (MODE_SIMULATE) return true;
|
||||
try{
|
||||
var obj_File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
|
||||
obj_File.initWithPath(str_Filename);
|
||||
if (!obj_File.exists())
|
||||
obj_File.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666 );
|
||||
|
||||
var obj_Transport = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
|
||||
|
||||
/* Open flags
|
||||
#define PR_RDONLY 0x01 - Open for reading only.
|
||||
#define PR_WRONLY 0x02 - Open for writing only.
|
||||
#define PR_RDWR 0x04 - Open for reading and writing.
|
||||
#define PR_CREATE_FILE 0x08 - If the file does not exist, the file is created. If the file exists, this flag has no effect.
|
||||
#define PR_APPEND 0x10 - The file pointer is set to the end of the file prior to each write.
|
||||
#define PR_TRUNCATE 0x20 - If the file exists, its length is truncated to 0.
|
||||
#define PR_SYNC 0x40 - If set, each write will wait for both the file data and file status to be physically updated.
|
||||
#define PR_EXCL 0x80 - With PR_CREATE_FILE, if the file does not exist, the file is created. If the file already exists, no action and NULL is returned.
|
||||
|
||||
File modes
|
||||
'mode' is currently only applicable on UNIX platforms.
|
||||
The 'mode' argument may be ignored by PR_Open on other platforms.
|
||||
00400 Read by owner.
|
||||
00200 Write by owner.
|
||||
00100 Execute (search if a directory) by owner.
|
||||
00040 Read by group.
|
||||
00020 Write by group.
|
||||
00010 Execute by group.
|
||||
00004 Read by others.
|
||||
00002 Write by others
|
||||
00001 Execute by others.
|
||||
*/
|
||||
obj_Transport.init( obj_File, 0x20 | 0x04 | 0x08, 064, 0 );
|
||||
obj_Transport.write(str_Buffer,str_Buffer.length);
|
||||
obj_Transport.flush();
|
||||
obj_Transport.close();
|
||||
return true;
|
||||
} catch (ex) {
|
||||
this.addError("[wpdCommon.writeFile]:\n -> str_Filename: "+str_Filename+"\n -> "+ex);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
|
||||
copyFile : function(sourcefile,destfile)
|
||||
{
|
||||
|
||||
var destdir=this.getFilePath(destfile);
|
||||
destfile=this.getFileLeafName(destfile);
|
||||
var aFile = Components.classes["@mozilla.org/file/local;1"]
|
||||
.createInstance(Components.interfaces.nsILocalFile);
|
||||
if (!aFile) return false;
|
||||
|
||||
var aDir = Components.classes["@mozilla.org/file/local;1"]
|
||||
.createInstance(Components.interfaces.nsILocalFile);
|
||||
if (!aDir) return false;
|
||||
|
||||
aFile.initWithPath(sourcefile);
|
||||
|
||||
aDir.initWithPath(destdir);
|
||||
|
||||
aFile.copyTo(aDir,destfile);
|
||||
return true; // Added by Dan S. for Zotero
|
||||
},
|
||||
|
||||
// download aSourceURL to aTargetFilename
|
||||
// (works also on local files...)
|
||||
downloadFile : function (aSourceURL,aTargetFilename)
|
||||
{
|
||||
if (MODE_SIMULATE) return true;
|
||||
try {
|
||||
//new obj_URI object
|
||||
var obj_URI = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService).newURI(aSourceURL, null, null);
|
||||
|
||||
//new file object
|
||||
var obj_TargetFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
|
||||
//set file with path
|
||||
// NOTE: This function has a known bug on the macintosh and other OSes
|
||||
// which do not represent file locations as paths. If you do use this
|
||||
// function, be very aware of this problem!
|
||||
obj_TargetFile.initWithPath(aTargetFilename);
|
||||
|
||||
//new persistence object
|
||||
var obj_Persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Components.interfaces.nsIWebBrowserPersist);
|
||||
|
||||
// set flags
|
||||
const nsIWBP = Components.interfaces.nsIWebBrowserPersist;
|
||||
var flags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
|
||||
nsIWBP.PERSIST_FLAGS_FROM_CACHE;
|
||||
//nsIWBP.PERSIST_FLAGS_BYPASS_CACHE;
|
||||
obj_Persist.persistFlags = flags;
|
||||
|
||||
// has the url the same filetype like the file extension?
|
||||
//save file to target
|
||||
obj_Persist.saveURI(obj_URI,null,null,null,null,obj_TargetFile);
|
||||
|
||||
return true;
|
||||
|
||||
} catch (ex) {
|
||||
aSourceURL=this.removeGETFromURL(aSourceURL);
|
||||
this.addError("[wpdCommon.downloadFile]:\n -> aSourceURL: "+aSourceURL.substring(aSourceURL.length-60)+"\n -> aTargetFilename: "+aTargetFilename+"\n -> "+ex);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
// get the integer preferences
|
||||
getIntPrefs : function (branch)
|
||||
{
|
||||
var mPrefSvc=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
|
||||
return mPrefSvc.getIntPref(branch);
|
||||
},
|
||||
|
||||
// set the integer preferences
|
||||
setIntPrefs : function (branch,value)
|
||||
{
|
||||
var mPrefSvc=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
|
||||
return mPrefSvc.setIntPref(branch,value);
|
||||
},
|
||||
|
||||
// get the integer preferences
|
||||
getStrPrefs : function (branch)
|
||||
{
|
||||
var mPrefSvc=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
|
||||
return mPrefSvc.getCharPref(branch);
|
||||
},
|
||||
|
||||
// set the string preferences
|
||||
setStrPrefs : function (branch,value)
|
||||
{
|
||||
var mPrefSvc=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
|
||||
return mPrefSvc.setCharPref(branch,value);
|
||||
},
|
||||
|
||||
// get the string preferences
|
||||
getStrPrefsEx : function (branch)
|
||||
{
|
||||
var mPrefSvc=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
||||
return mPrefSvc.getComplexValue(branch,Components.interfaces.nsISupportsString).data;
|
||||
},
|
||||
|
||||
// set the string preferences
|
||||
setStrPrefsEx : function (branch,value)
|
||||
{
|
||||
var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
|
||||
str.data = value;
|
||||
var mPrefSvc=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
||||
return mPrefSvc.setComplexValue(branch,Components.interfaces.nsISupportsString,str);
|
||||
},
|
||||
|
||||
|
||||
// Get the preferences branch ("browser.download." for normal 'save' mode)...
|
||||
setBoolPrefs : function (branch,value)
|
||||
{
|
||||
var mPrefSvc=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
|
||||
return mPrefSvc.setBoolPref(branch,value);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
1029
chrome/content/zotero/webpagedump/domsaver.js
Normal file
1029
chrome/content/zotero/webpagedump/domsaver.js
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -38,6 +38,7 @@ Zotero.Attachments = new function(){
|
|||
|
||||
var self = this;
|
||||
|
||||
|
||||
function importFromFile(file, sourceItemID){
|
||||
Zotero.debug('Importing attachment from file');
|
||||
|
||||
|
@ -167,7 +168,7 @@ Zotero.Attachments = new function(){
|
|||
}
|
||||
|
||||
|
||||
function importFromURL(url, sourceItemID, forceTitle, parentCollectionIDs){
|
||||
function importFromURL(url, sourceItemID, forceTitle, forceFileName, parentCollectionIDs){
|
||||
Zotero.debug('Importing attachment from URL');
|
||||
|
||||
Zotero.Utilities.HTTP.doHead(url, function(obj){
|
||||
|
@ -190,6 +191,17 @@ Zotero.Attachments = new function(){
|
|||
if (Zotero.MIME.hasNativeHandler(mimeType, ext)){
|
||||
var browser = Zotero.Browser.createHiddenBrowser();
|
||||
browser.addEventListener("pageshow", function(){
|
||||
try {
|
||||
Zotero.Attachments.importFromDocument(browser.contentDocument,
|
||||
sourceItemID, forceTitle, forceFileName, parentCollectionIDs);
|
||||
}
|
||||
finally {
|
||||
browser.removeEventListener("pageshow", arguments.callee, true);
|
||||
Zotero.Browser.deleteHiddenBrowser(browser);
|
||||
}
|
||||
|
||||
/* Built-in method -- disabled in favor of WebPageDump
|
||||
|
||||
var callback = function () {
|
||||
browser.removeEventListener("pageshow", arguments.callee, true);
|
||||
Zotero.Browser.deleteHiddenBrowser(browser);
|
||||
|
@ -197,6 +209,7 @@ Zotero.Attachments = new function(){
|
|||
|
||||
Zotero.Attachments.importFromDocument(browser.contentDocument,
|
||||
sourceItemID, forceTitle, parentCollectionIDs, callback);
|
||||
*/
|
||||
}, true);
|
||||
browser.loadURI(url);
|
||||
}
|
||||
|
@ -356,6 +369,8 @@ Zotero.Attachments = new function(){
|
|||
var mimeType = document.contentType;
|
||||
var charsetID = Zotero.CharacterSets.getID(document.characterSet);
|
||||
|
||||
Zotero.DB.beginTransaction();
|
||||
|
||||
var itemID = _addToDB(null, url, title, this.LINK_MODE_LINKED_URL,
|
||||
mimeType, charsetID, sourceItemID);
|
||||
|
||||
|
@ -368,6 +383,8 @@ Zotero.Attachments = new function(){
|
|||
}
|
||||
}
|
||||
|
||||
Zotero.DB.commitTransaction();
|
||||
|
||||
// Run the fulltext indexer asynchronously (actually, it hangs the UI
|
||||
// thread, but at least it lets the menu close)
|
||||
setTimeout(function() {
|
||||
|
@ -383,6 +400,108 @@ Zotero.Attachments = new function(){
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* Save a snapshot -- uses synchronous WebPageDump
|
||||
*
|
||||
* Returns itemID of attachment
|
||||
*/
|
||||
function importFromDocument(document, sourceItemID, forceTitle, forceFileName, parentCollectionIDs) {
|
||||
Zotero.debug('Importing attachment from document');
|
||||
|
||||
var url = document.location.href;
|
||||
var title = forceTitle ? forceTitle : document.title;
|
||||
var mimeType = document.contentType;
|
||||
var charsetID = Zotero.CharacterSets.getID(document.characterSet);
|
||||
|
||||
if (!forceTitle) {
|
||||
// Remove e.g. " - Scaled (-17%)" from end of images saved from links,
|
||||
// though I'm not sure why it's getting added to begin with
|
||||
if (mimeType.indexOf('image/') === 0) {
|
||||
title = title.replace(/(.+ \([^,]+, [0-9]+x[0-9]+[^\)]+\)) - .+/, "$1" );
|
||||
}
|
||||
// If not native type, strip mime type data in parens
|
||||
else if (!Zotero.MIME.hasNativeHandler(mimeType, _getExtensionFromURL(url))) {
|
||||
title = title.replace(/(.+) \([a-z]+\/[^\)]+\)/, "$1" );
|
||||
}
|
||||
}
|
||||
|
||||
Zotero.DB.beginTransaction();
|
||||
|
||||
try {
|
||||
// Create a new attachment
|
||||
var attachmentItem = new Zotero.Item('attachment');
|
||||
attachmentItem.setField('title', title);
|
||||
attachmentItem.setField('url', url);
|
||||
attachmentItem.setField('accessDate', "CURRENT_TIMESTAMP");
|
||||
var itemID = attachmentItem.save();
|
||||
|
||||
// Create a new folder for this item in the storage directory
|
||||
var destDir = this.createDirectoryForItem(itemID);
|
||||
|
||||
var file = Components.classes["@mozilla.org/file/local;1"].
|
||||
createInstance(Components.interfaces.nsILocalFile);
|
||||
file.initWithFile(destDir);
|
||||
|
||||
var fileName = _getFileNameFromURL(url, mimeType);
|
||||
|
||||
file.append(fileName);
|
||||
|
||||
// Load WebPageDump code
|
||||
Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader)
|
||||
.loadSubScript("chrome://zotero/content/webpagedump/common.js");
|
||||
|
||||
Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader)
|
||||
.loadSubScript("chrome://zotero/content/webpagedump/domsaver.js");
|
||||
|
||||
wpdDOMSaver.init(file.path, document)
|
||||
wpdDOMSaver.saveHTMLDocument()
|
||||
|
||||
_addToDB(file, url, title, Zotero.Attachments.LINK_MODE_IMPORTED_URL,
|
||||
mimeType, charsetID, sourceItemID, itemID);
|
||||
|
||||
Zotero.Notifier.trigger('add', 'item', itemID);
|
||||
|
||||
// Add to collections
|
||||
if (parentCollectionIDs){
|
||||
var ids = Zotero.flattenArguments(parentCollectionIDs);
|
||||
for each(var id in ids){
|
||||
var col = Zotero.Collections.get(id);
|
||||
col.addItem(itemID);
|
||||
}
|
||||
}
|
||||
|
||||
Zotero.DB.commitTransaction();
|
||||
|
||||
Zotero.Fulltext.indexDocument(document, itemID);
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.DB.rollbackTransaction();
|
||||
|
||||
try {
|
||||
// Clean up
|
||||
if (itemID) {
|
||||
var destDir = Zotero.getStorageDirectory();
|
||||
destDir.append(itemID);
|
||||
if (destDir.exists()) {
|
||||
destDir.remove(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
throw (e);
|
||||
}
|
||||
|
||||
return itemID;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Previous asynchronous snapshot method -- disabled in favor of WebPageDump
|
||||
*/
|
||||
/*
|
||||
function importFromDocument(document, sourceItemID, forceTitle, parentCollectionIDs, callback){
|
||||
Zotero.debug('Importing attachment from document');
|
||||
|
||||
|
@ -521,6 +640,7 @@ Zotero.Attachments = new function(){
|
|||
throw (e);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
@ -108,7 +108,7 @@ Zotero.CollectionTreeView.prototype.reload = function()
|
|||
var oldCount = this.rowCount;
|
||||
this._treebox.beginUpdateBatch();
|
||||
this.refresh();
|
||||
this._treebox.rowCountChanged(0,this.rowCount - oldCount);
|
||||
this._treebox.rowCountChanged(this.rowCount, this.rowCount - oldCount);
|
||||
|
||||
for(var i = 0; i < openCollections.length; i++)
|
||||
{
|
||||
|
@ -213,7 +213,6 @@ Zotero.CollectionTreeView.prototype.notify = function(action, type, ids)
|
|||
if (parentID) {
|
||||
if (!this.isContainerOpen(this._collectionRowMap[parentID])){
|
||||
this.toggleOpenState(this._collectionRowMap[parentID]);
|
||||
this._refreshHashMap();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -667,7 +666,7 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient)
|
|||
var parentCollectionID = false;
|
||||
}
|
||||
|
||||
Zotero.Attachments.importFromURL(url, false, false, parentCollectionID);
|
||||
Zotero.Attachments.importFromURL(url, false, false, false, parentCollectionID);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -902,7 +902,6 @@ Zotero.Item.prototype.save = function(){
|
|||
sql = "INSERT INTO itemData VALUES (?,?,?)";
|
||||
var insertStatement = Zotero.DB.getStatement(sql);
|
||||
|
||||
Zotero.debug(this._changedItemData.items);
|
||||
for (fieldID in this._changedItemData.items){
|
||||
var value = this.getField(fieldID, true);
|
||||
if (!value) {
|
||||
|
|
|
@ -759,7 +759,7 @@ Zotero.Ingester.MIMEHandler.StreamListener.prototype.onStopRequest = function(ch
|
|||
if(!translators.length) {
|
||||
// we lied. we can't really translate this file. call
|
||||
// nsIExternalHelperAppService with the data
|
||||
frontWindow.Zotero_Browser.Progress.kill();
|
||||
frontWindow.Zotero_Browser.progress.close();
|
||||
|
||||
var streamListener;
|
||||
if(streamListener = externalHelperAppService.doContent(this._contentType, this._request, frontWindow)) {
|
||||
|
|
|
@ -85,7 +85,9 @@ Zotero.ItemTreeView.prototype.setTree = function(treebox)
|
|||
|
||||
this._treebox = treebox;
|
||||
|
||||
this._ownerDocument.defaultView.ZoteroPane.setItemsPaneMessage(Zotero.getString('pane.items.loading'));
|
||||
if (this._ownerDocument.defaultView.ZoteroPane) {
|
||||
this._ownerDocument.defaultView.ZoteroPane.setItemsPaneMessage(Zotero.getString('pane.items.loading'));
|
||||
}
|
||||
|
||||
// Generate the tree contents in a timer to allow message above to display
|
||||
var paneLoader = function(obj) {
|
||||
|
@ -114,7 +116,9 @@ Zotero.ItemTreeView.prototype.setTree = function(treebox)
|
|||
//Zotero.debug('Running callbacks in itemTreeView.setTree()', 4);
|
||||
obj._runCallbacks();
|
||||
|
||||
obj._ownerDocument.defaultView.ZoteroPane.clearItemsPaneMessage();
|
||||
if (obj._ownerDocument.defaultView.ZoteroPane) {
|
||||
obj._ownerDocument.defaultView.ZoteroPane.clearItemsPaneMessage();
|
||||
}
|
||||
}
|
||||
|
||||
this._ownerDocument.defaultView.setTimeout(paneLoader, 50, this);
|
||||
|
@ -128,7 +132,6 @@ Zotero.ItemTreeView.prototype.setTree = function(treebox)
|
|||
Zotero.ItemTreeView.prototype.refresh = function()
|
||||
{
|
||||
var oldRows = this.rowCount;
|
||||
|
||||
this._dataItems = [];
|
||||
this.rowCount = 0;
|
||||
|
||||
|
@ -248,11 +251,12 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids)
|
|||
for(var i=0, len=ids.length; i<len; i++)
|
||||
{
|
||||
var row = this._itemRowMap[ids[i]];
|
||||
var sourceItemID = this._getItemAtRow(row).ref.getSource();
|
||||
var parentIndex = this.getParentIndex(row);
|
||||
// Item already exists in this view
|
||||
if( row != null)
|
||||
{
|
||||
var sourceItemID = this._getItemAtRow(row).ref.getSource();
|
||||
var parentIndex = this.getParentIndex(row);
|
||||
|
||||
if (this.isContainer(row) && this.isContainerOpen(row))
|
||||
{
|
||||
this.toggleOpenState(row);
|
||||
|
@ -277,7 +281,6 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids)
|
|||
}
|
||||
// If not moved from under one item to another
|
||||
else if (parentIndex == -1 || !sourceItemID) {
|
||||
Zotero.debug('here');
|
||||
sort = ids[i];
|
||||
}
|
||||
madeChanges = true;
|
||||
|
@ -776,7 +779,6 @@ Zotero.ItemTreeView.prototype.sort = function(itemID)
|
|||
if (itemID) {
|
||||
this._refreshHashMap();
|
||||
var row = this._itemRowMap[itemID];
|
||||
Zotero.debug(row);
|
||||
for (var i=0, len=this._dataItems.length; i<len; i++) {
|
||||
if (i == row) {
|
||||
continue;
|
||||
|
@ -1475,7 +1477,7 @@ Zotero.ItemTreeView.prototype.drop = function(row, orient)
|
|||
var parentCollectionID = this._itemGroup.ref.getID();
|
||||
}
|
||||
|
||||
Zotero.Attachments.importFromURL(url, sourceItemID, false, parentCollectionID);
|
||||
Zotero.Attachments.importFromURL(url, sourceItemID, false, false, parentCollectionID);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,9 @@ Zotero.ProgressWindowSet = new function() {
|
|||
}
|
||||
|
||||
for (var i=0; i<_progressWindows.length; i++) {
|
||||
_progressWindows[i].instance.fade();
|
||||
// Pass |requireMouseOver| so that the window only closes
|
||||
// if the mouse was over it at some point
|
||||
_progressWindows[i].instance.startCloseTimer(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,8 +113,8 @@ Zotero.ProgressWindow = function(_window){
|
|||
this.changeHeadline = changeHeadline;
|
||||
this.addLines = addLines;
|
||||
this.addDescription = addDescription;
|
||||
this.fade = fade;
|
||||
this.kill = kill;
|
||||
this.startCloseTimer = startCloseTimer;
|
||||
this.close = close;
|
||||
|
||||
var _window = null;
|
||||
|
||||
|
@ -120,6 +122,7 @@ Zotero.ProgressWindow = function(_window){
|
|||
var _windowLoaded = false;
|
||||
var _windowLoading = false;
|
||||
var _timeoutID = false;
|
||||
var _mouseWasOver = false
|
||||
|
||||
// keep track of all of these things in case they're called before we're
|
||||
// done loading the progress window
|
||||
|
@ -243,21 +246,26 @@ Zotero.ProgressWindow = function(_window){
|
|||
}
|
||||
|
||||
|
||||
function fade() {
|
||||
function startCloseTimer(requireMouseOver) {
|
||||
if (_windowLoaded || _windowLoading) {
|
||||
if (_timeoutID) {
|
||||
if (requireMouseOver && !_mouseWasOver) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_timeoutID) {
|
||||
_disableTimeout();
|
||||
}
|
||||
|
||||
_timeoutID = _progressWindow.setTimeout(_timeout, 2500);
|
||||
}
|
||||
}
|
||||
|
||||
function kill() {
|
||||
function close() {
|
||||
_disableTimeout();
|
||||
_windowLoaded = false;
|
||||
_windowLoading = false;
|
||||
Zotero.ProgressWindowSet.remove(_progressWindow);
|
||||
|
||||
try {
|
||||
_progressWindow.close();
|
||||
} catch(ex) {}
|
||||
|
@ -288,7 +296,7 @@ Zotero.ProgressWindow = function(_window){
|
|||
}
|
||||
|
||||
function _timeout() {
|
||||
kill(); // could check to see if we're really supposed to fade yet
|
||||
close(); // could check to see if we're really supposed to close yet
|
||||
// (in case multiple scrapers are operating at once)
|
||||
_timeoutID = false;
|
||||
}
|
||||
|
@ -300,20 +308,21 @@ Zotero.ProgressWindow = function(_window){
|
|||
|
||||
|
||||
/*
|
||||
* Disable the fade timer when the mouse is over the window
|
||||
* Disable the close timer when the mouse is over the window
|
||||
*/
|
||||
function _onMouseOver(e) {
|
||||
_mouseWasOver = true;
|
||||
_disableTimeout();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Start the fade timer when the mouse leaves the window
|
||||
* Start the close timer when the mouse leaves the window
|
||||
*
|
||||
* Note that this onmouseout doesn't work correctly on popups in Fx2,
|
||||
* so 1) we have to calculate the window borders manually to avoid fading
|
||||
* when the mouse is still over the box, and 2) this only does anything
|
||||
* when the mouse is moved off of the browser window -- otherwise the fade
|
||||
* when the mouse is moved off of the browser window -- otherwise the close
|
||||
* is triggered by onmousemove on appcontent in overlay.xul.
|
||||
*/
|
||||
function _onMouseOut(e) {
|
||||
|
@ -324,12 +333,12 @@ Zotero.ProgressWindow = function(_window){
|
|||
return;
|
||||
}
|
||||
|
||||
fade();
|
||||
startCloseTimer();
|
||||
}
|
||||
|
||||
|
||||
function _onMouseUp(e) {
|
||||
kill();
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<!ENTITY zotero.preferences.fontSize.medium "Medium">
|
||||
<!ENTITY zotero.preferences.fontSize.large "Large">
|
||||
|
||||
<!ENTITY zotero.preferences.miscellaneous "Miscellaneous">
|
||||
<!ENTITY zotero.preferences.autoUpdate "Automatically check for updated scrapers">
|
||||
<!ENTITY zotero.preferences.updateNow "Update now">
|
||||
<!ENTITY zotero.preferences.reportTranslationFailure "Report broken site translators">
|
||||
|
@ -31,7 +32,7 @@
|
|||
|
||||
<!ENTITY zotero.preferences.quickCopy.caption "Quick Copy">
|
||||
<!ENTITY zotero.preferences.quickCopy.outputFormat "Output Format:">
|
||||
<!ENTITY zotero.preferences.quickCopy.macWarning "Note that some formatting may be lost on Mac OS X.">
|
||||
<!ENTITY zotero.preferences.quickCopy.macWarning "Note that rich-text formatting will be lost on Mac OS X.">
|
||||
|
||||
|
||||
<!ENTITY zotero.preferences.prefpane.keys "Shortcut Keys">
|
||||
|
|
|
@ -81,7 +81,7 @@
|
|||
<!ENTITY zotero.bibliography.saveAsRTF.label "Save as RTF">
|
||||
<!ENTITY zotero.bibliography.saveAsHTML.label "Save as HTML">
|
||||
<!ENTITY zotero.bibliography.copyToClipboard.label "Copy to Clipboard">
|
||||
<!ENTITY zotero.bibliography.macClipboardWarning "(Some formatting may be lost.)">
|
||||
<!ENTITY zotero.bibliography.macClipboardWarning "(Rich-text formatting will be lost.)">
|
||||
<!ENTITY zotero.bibliography.print.label "Print">
|
||||
|
||||
<!ENTITY zotero.integration.docPrefs.title "Document Preferences">
|
||||
|
|
|
@ -269,6 +269,9 @@ fileTypes.video = Video
|
|||
fileTypes.presentation = Presentation
|
||||
fileTypes.document = Document
|
||||
|
||||
save.attachment = Saving Snapshot...
|
||||
save.link = Saving Link...
|
||||
|
||||
ingester.scraping = Saving Item...
|
||||
ingester.scrapeComplete = Item Saved
|
||||
ingester.scrapeError = Could Not Save Item
|
||||
|
|
|
@ -28,14 +28,13 @@ radio[pane=zotero-prefpane-general][selected="true"]
|
|||
*/
|
||||
radio[pane=zotero-prefpane-export]
|
||||
{
|
||||
list-style-image: url("chrome://browser/skin/Toolbar.png");
|
||||
-moz-image-region: rect(0px, 312px, 24px, 288px);
|
||||
-moz-image-region: rect(0px, 224px, 32px, 192px);
|
||||
}
|
||||
radio[pane=zotero-prefpane-export]:hover,
|
||||
radio[pane=zotero-prefpane-export]:active,
|
||||
radio[pane=zotero-prefpane-export][selected="true"]
|
||||
{
|
||||
-moz-image-region: rect(24px, 312px, 48px, 288px);
|
||||
-moz-image-region: rect(32px, 224px, 64px, 192px);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue
Block a user