Merge commit '920df48d1da4f9bf33bf1a01c60a2131e589d29c' into 3.0
This commit is contained in:
commit
f6c3f58bc2
|
@ -33,7 +33,6 @@
|
|||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
// "WebPageDump" Firefox Extension
|
||||
// --------------------------------------------------------------------------------
|
||||
|
@ -42,8 +41,6 @@
|
|||
// provides common functions (file, preferences, windows, error,...)
|
||||
//
|
||||
// --------------------------------------------------------------------------------
|
||||
|
||||
|
||||
var gBrowserWindow = null;
|
||||
var gExceptLocation = "about:blank";
|
||||
var gCallback = "";
|
||||
|
@ -74,11 +71,11 @@ var WPD_MAXUIERRORCOUNT=8;
|
|||
/* [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);
|
||||
[14:55:50]
|
||||
var windowMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
|
||||
*/
|
||||
|
||||
function wpdGetTopBrowserWindow()
|
||||
{
|
||||
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");
|
||||
|
@ -90,8 +87,7 @@ function wpdGetTopBrowserWindow()
|
|||
}
|
||||
|
||||
|
||||
function wpdWindowLoaded()
|
||||
{
|
||||
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");
|
||||
|
@ -116,8 +112,7 @@ function wpdWindowLoaded()
|
|||
}
|
||||
}
|
||||
|
||||
function wpdTimeOut()
|
||||
{
|
||||
function wpdTimeOut() {
|
||||
Zotero.debug("[wpdTimeOut] timeout triggered!");
|
||||
gTimedOut = true;
|
||||
gBrowserWindow.clearTimeout(gTimeOutID);
|
||||
|
@ -125,13 +120,11 @@ function wpdTimeOut()
|
|||
gBrowserWindow.setTimeout(gCallback, 0);
|
||||
}
|
||||
|
||||
function wpdIsTimedOut()
|
||||
{
|
||||
function wpdIsTimedOut() {
|
||||
return gTimedOut;
|
||||
}
|
||||
|
||||
function wpdLoadURL(aURI,aCallback)
|
||||
{
|
||||
function wpdLoadURL(aURI, aCallback) {
|
||||
try {
|
||||
gTimedOut = false;
|
||||
Zotero.debug("[wpdLoadURL] aURI: " + aURI);
|
||||
|
@ -193,8 +186,7 @@ var wpdCommon = {
|
|||
|
||||
// checks the CRLFs at the beginning - if there are CRLFs present
|
||||
// one additional CRLF will be added at the beginning
|
||||
checkCRLF : function (aNode)
|
||||
{
|
||||
checkCRLF: function (aNode) {
|
||||
try {
|
||||
var before = false;
|
||||
var after = false;
|
||||
|
@ -231,8 +223,7 @@ var wpdCommon = {
|
|||
}
|
||||
},
|
||||
|
||||
unicodeToEntity : function (text,charset)
|
||||
{
|
||||
unicodeToEntity: function (text, charset) {
|
||||
|
||||
function convertEntity(letter) {
|
||||
try {
|
||||
|
@ -243,8 +234,7 @@ var wpdCommon = {
|
|||
} else if ((l != letter)) {
|
||||
return "&#" + letter.charCodeAt(0) + ";";
|
||||
}
|
||||
} catch (ex) {
|
||||
}
|
||||
} 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 {
|
||||
|
@ -252,8 +242,7 @@ var wpdCommon = {
|
|||
if ((charset != "UTF-8") && (s == "?")) {
|
||||
return "&#" + letter.charCodeAt(0) + ";";
|
||||
}
|
||||
} catch (ex) {
|
||||
}
|
||||
} catch (ex) {}
|
||||
return letter;
|
||||
}
|
||||
|
||||
|
@ -293,25 +282,21 @@ var wpdCommon = {
|
|||
},
|
||||
|
||||
|
||||
playSound : function()
|
||||
{
|
||||
playSound: function () {
|
||||
try {
|
||||
var sound = Components.classes["@mozilla.org/sound;1"].createInstance(Components.interfaces.nsISound);
|
||||
sound.playSystemSound("ringin.wav");
|
||||
} catch(ex) {
|
||||
}
|
||||
} catch (ex) {}
|
||||
},
|
||||
|
||||
// return the current focused window
|
||||
getFocusedWindow : function()
|
||||
{
|
||||
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)
|
||||
{
|
||||
sizeWindow: function (w, h) {
|
||||
try {
|
||||
var window = this.getFocusedWindow();
|
||||
window.moveTo(0, 0);
|
||||
|
@ -319,13 +304,11 @@ var wpdCommon = {
|
|||
if ((h == 0) || (w > screen.availHeight)) h = screen.availHeight;
|
||||
window.resizeTo(w, h);
|
||||
window.focus();
|
||||
} catch(ex) {
|
||||
}
|
||||
} catch (ex) {}
|
||||
},
|
||||
|
||||
// add a line to the error list (displays a maximum of 15 errors)
|
||||
addError : function(aError)
|
||||
{
|
||||
addError: function (aError) {
|
||||
Zotero.debug('ERROR: ' + aError);
|
||||
if (this.errCount < WPD_MAXUIERRORCOUNT) {
|
||||
if (this.errList.indexOf(aError) > -1) return; // is the same
|
||||
|
@ -348,8 +331,7 @@ var wpdCommon = {
|
|||
},
|
||||
|
||||
// returns num as string of length i filled up with 0s
|
||||
addLeftZeros : function(num,i)
|
||||
{
|
||||
addLeftZeros: function (num, i) {
|
||||
var s = "" + num;
|
||||
var r = "";
|
||||
for (var f = 0; f < i - s.length; f++) r = r + "0";
|
||||
|
@ -357,8 +339,7 @@ var wpdCommon = {
|
|||
},
|
||||
|
||||
// split the filename in filename and extension
|
||||
splitFileName : function(aFileName)
|
||||
{
|
||||
splitFileName: function (aFileName) {
|
||||
var pos = aFileName.lastIndexOf(".");
|
||||
var ret = [];
|
||||
if (pos != -1) {
|
||||
|
@ -372,8 +353,7 @@ var wpdCommon = {
|
|||
},
|
||||
|
||||
// replace illegal characters
|
||||
getValidFileName : function(aFileName)
|
||||
{
|
||||
getValidFileName: function (aFileName) {
|
||||
aFileName = aFileName.replace(/[\"\?!~`]+/g, "");
|
||||
aFileName = aFileName.replace(/[\*\&]+/g, "+");
|
||||
aFileName = aFileName.replace(/[\\\/\|\:;]+/g, "-");
|
||||
|
@ -384,14 +364,12 @@ var wpdCommon = {
|
|||
return aFileName;
|
||||
},
|
||||
|
||||
getURL : function()
|
||||
{
|
||||
getURL: function () {
|
||||
return top.window._content.document.location.href;
|
||||
},
|
||||
|
||||
// remove get variables from an URL
|
||||
removeGETFromURL : function(aURL)
|
||||
{
|
||||
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;
|
||||
|
@ -399,24 +377,21 @@ var wpdCommon = {
|
|||
},
|
||||
|
||||
// extract filename from URL
|
||||
getFileName : function(aURL)
|
||||
{
|
||||
getFileName: function (aURL) {
|
||||
var pos;
|
||||
aURL = this.removeGETFromURL(aURL);
|
||||
aURL = ((pos = aURL.lastIndexOf("/")) != -1) ? aURL.substring(++pos) : aURL;
|
||||
return aURL;
|
||||
},
|
||||
|
||||
filePathToURI: function(filePath)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
@ -426,31 +401,27 @@ var wpdCommon = {
|
|||
},
|
||||
|
||||
// right part of filepath/filename
|
||||
getFileLeafName: function(filePath)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
pathExists: function (filePath) {
|
||||
var obj_File = Components.classes["@mozilla.org/file/local;1"].getService(Components.interfaces.nsILocalFile);
|
||||
try {
|
||||
obj_File.initWithPath(filePath);
|
||||
|
@ -461,18 +432,17 @@ var wpdCommon = {
|
|||
},
|
||||
|
||||
// add the HTML Tag Stuff to aNode and embedd the aNode.innerHTML between the tags
|
||||
nodeToHTMLString: function(aNode)
|
||||
{
|
||||
nodeToHTMLString: function (aNode) {
|
||||
if (aNode == null) return "";
|
||||
var tag = "<" + aNode.nodeName.toLowerCase();
|
||||
for ( var i=0; i<aNode.attributes.length; i++ )
|
||||
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)
|
||||
{
|
||||
ConvertFromUnicode16: function (aString, charset) {
|
||||
if (!aString) return "";
|
||||
try {
|
||||
var UNICODE = Components.classes['@mozilla.org/intl/scriptableunicodeconverter'].getService(Components.interfaces.nsIScriptableUnicodeConverter);
|
||||
|
@ -485,8 +455,7 @@ var wpdCommon = {
|
|||
return aString;
|
||||
},
|
||||
|
||||
ConvertToUnicode16 : function(aString,charset)
|
||||
{
|
||||
ConvertToUnicode16: function (aString, charset) {
|
||||
if (!aString) return "";
|
||||
try {
|
||||
var UNICODE = Components.classes['@mozilla.org/intl/scriptableunicodeconverter'].getService(Components.interfaces.nsIScriptableUnicodeConverter);
|
||||
|
@ -499,8 +468,7 @@ var wpdCommon = {
|
|||
},
|
||||
|
||||
// convert the doctype to an HTML doctype String
|
||||
doctypeToHTMLString : function(aDoctype)
|
||||
{
|
||||
doctypeToHTMLString: function (aDoctype) {
|
||||
if (!aDoctype) return "";
|
||||
var ret = "<!DOCTYPE " + aDoctype.name;
|
||||
if (aDoctype.publicId) ret += ' PUBLIC "' + aDoctype.publicId + '"';
|
||||
|
@ -509,16 +477,14 @@ var wpdCommon = {
|
|||
return ret;
|
||||
},
|
||||
|
||||
addCommentTag : function(targetNode, aComment)
|
||||
{
|
||||
addCommentTag: function (targetNode, aComment) {
|
||||
targetNode.appendChild(document.createTextNode("\n"));
|
||||
targetNode.appendChild(document.createComment(aComment));
|
||||
targetNode.appendChild(document.createTextNode("\n"));
|
||||
},
|
||||
|
||||
|
||||
removeNodeFromParent : function(aNode)
|
||||
{
|
||||
removeNodeFromParent: function (aNode) {
|
||||
// Added by Dan S. for Zotero
|
||||
var document = aNode.ownerDocument;
|
||||
|
||||
|
@ -530,16 +496,14 @@ var wpdCommon = {
|
|||
|
||||
// convert URL String to Object
|
||||
// for easier URL handling
|
||||
convertURLToObject : function(aURLString)
|
||||
{
|
||||
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)
|
||||
{
|
||||
resolveURL: function (aBaseURL, aRelURL) {
|
||||
try {
|
||||
var aBaseURLObj = this.convertURLToObject(aBaseURL);
|
||||
return aBaseURLObj.resolve(aRelURL);
|
||||
|
@ -549,8 +513,7 @@ var wpdCommon = {
|
|||
return "";
|
||||
},
|
||||
|
||||
getHostName : function(aURL)
|
||||
{
|
||||
getHostName: function (aURL) {
|
||||
try {
|
||||
var aURLObj = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURI);
|
||||
aURLObj.spec = aURL
|
||||
|
@ -561,8 +524,7 @@ var wpdCommon = {
|
|||
return "";
|
||||
},
|
||||
|
||||
convertUrlToASCII : function(aURL)
|
||||
{
|
||||
convertUrlToASCII: function (aURL) {
|
||||
try {
|
||||
var aURLObj = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURI);
|
||||
aURLObj.spec = aURL
|
||||
|
@ -573,32 +535,27 @@ var wpdCommon = {
|
|||
return "";
|
||||
},
|
||||
|
||||
createDir : function(str_Dir)
|
||||
{
|
||||
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);
|
||||
if (!obj_File.exists()) obj_File.create(obj_File.DIRECTORY_TYPE, 0700);
|
||||
},
|
||||
|
||||
readDir : function(str_Dir)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
@ -629,14 +586,12 @@ var wpdCommon = {
|
|||
},
|
||||
|
||||
// write the String Buffer (str_Buffer) to a file (str_Filename)
|
||||
writeFile : function(str_Buffer,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 );
|
||||
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);
|
||||
|
||||
|
@ -675,17 +630,14 @@ var wpdCommon = {
|
|||
},
|
||||
|
||||
|
||||
copyFile : function(sourcefile,destfile)
|
||||
{
|
||||
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);
|
||||
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);
|
||||
var aDir = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
|
||||
if (!aDir) return false;
|
||||
|
||||
aFile.initWithPath(sourcefile);
|
||||
|
@ -698,8 +650,7 @@ var wpdCommon = {
|
|||
|
||||
// download aSourceURL to aTargetFilename
|
||||
// (works also on local files...)
|
||||
downloadFile : function (aSourceURL,aTargetFilename)
|
||||
{
|
||||
downloadFile: function (aSourceURL, aTargetFilename) {
|
||||
if (MODE_SIMULATE) return true;
|
||||
try {
|
||||
//new obj_URI object
|
||||
|
@ -718,8 +669,7 @@ var wpdCommon = {
|
|||
|
||||
// set flags
|
||||
const nsIWBP = Components.interfaces.nsIWebBrowserPersist;
|
||||
var flags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
|
||||
nsIWBP.PERSIST_FLAGS_FROM_CACHE;
|
||||
var flags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES | nsIWBP.PERSIST_FLAGS_FROM_CACHE;
|
||||
//nsIWBP.PERSIST_FLAGS_BYPASS_CACHE;
|
||||
obj_Persist.persistFlags = flags;
|
||||
|
||||
|
@ -737,43 +687,37 @@ var wpdCommon = {
|
|||
},
|
||||
|
||||
// get the integer preferences
|
||||
getIntPrefs : function (branch)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
@ -782,12 +726,9 @@ var wpdCommon = {
|
|||
|
||||
|
||||
// Get the preferences branch ("browser.download." for normal 'save' mode)...
|
||||
setBoolPrefs : function (branch,value)
|
||||
{
|
||||
setBoolPrefs: function (branch, value) {
|
||||
var mPrefSvc = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
|
||||
return mPrefSvc.setBoolPref(branch, value);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
// "WebPageDump" Firefox Extension
|
||||
// --------------------------------------------------------------------------------
|
||||
|
@ -67,9 +66,7 @@
|
|||
//
|
||||
// --------------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
//
|
||||
|
||||
// TO DO: use version information from rdf file...
|
||||
var WPD_VERSION = "0.2";
|
||||
|
||||
|
@ -88,7 +85,7 @@ var WPD_CRLFBUG = true;
|
|||
// the ConvertToEntities XPCOM function for generating usual
|
||||
// HTML Entities...
|
||||
// (this is precisely not a bug but a concept failure)
|
||||
var WPD_ENTITYBUG = true;
|
||||
var WPD_ENTITYBUG = false;
|
||||
|
||||
// CSSSCROLLBUG: The css "scroll" property of "background" is
|
||||
// loosing the zero vertical position leading to a false
|
||||
|
@ -109,7 +106,7 @@ var WPD_CSSBACKGROUNDPOSITIONBUG = true;
|
|||
// leave the doctype at the original position before the
|
||||
// HTML tag <HTML> and insert the doctype entry a second
|
||||
// time below the <HTML> tag...
|
||||
var WPD_DOCTYPEBUG = true;
|
||||
var WPD_DOCTYPEBUG = false;
|
||||
|
||||
// JAVASCRIPTSRCBUG: Deleting the "src" attribute together
|
||||
// with the whole <SCRIPT> tag may result in unexpected
|
||||
|
@ -145,8 +142,7 @@ var wpdDOMSaver = {
|
|||
dateObj: null,
|
||||
|
||||
// initialize the properties (set document, URL, Directory, ...)
|
||||
init : function(fileName, document)
|
||||
{
|
||||
init: function (fileName, document) {
|
||||
Zotero.debug("[wpdDOMSaver.init] ...");
|
||||
|
||||
this.name = "";
|
||||
|
@ -213,11 +209,9 @@ var wpdDOMSaver = {
|
|||
|
||||
|
||||
// get all frames in the document (recursively) and save in this.frameList
|
||||
setFrameList : function(aDocument)
|
||||
{
|
||||
setFrameList: function (aDocument) {
|
||||
try {
|
||||
for ( var f=0; f<aDocument.frames.length; f++ )
|
||||
{
|
||||
for (var f = 0; f < aDocument.frames.length; f++) {
|
||||
this.frameList.push(aDocument.frames[f]);
|
||||
this.setFrameList(aDocument.frames[f]);
|
||||
}
|
||||
|
@ -225,8 +219,7 @@ var wpdDOMSaver = {
|
|||
},
|
||||
|
||||
// resolve the javascript links inside the attributes (e.g. onclick,...)
|
||||
normalizeJavaScriptLink : function(aNode, aAttr)
|
||||
{
|
||||
normalizeJavaScriptLink: function (aNode, aAttr) {
|
||||
var val = aNode.getAttribute(aAttr); // get the attribute value and check for link stuff
|
||||
if (!val.match(/\(\'([^\']+)\'/)) return aNode;
|
||||
val = RegExp.$1;
|
||||
|
@ -250,17 +243,37 @@ var wpdDOMSaver = {
|
|||
},
|
||||
|
||||
// check if the file extension of the url is specified in the options array
|
||||
checkFileTypeOptions : function (aURL)
|
||||
{
|
||||
checkFileTypeOptions: function (aURL) {
|
||||
var ext = wpdCommon.splitFileName(wpdCommon.getFileName(aURL))[1].toLowerCase();
|
||||
var flag = false;
|
||||
switch ( ext )
|
||||
{
|
||||
case "jpg" : case "jpeg" : case "png" : case "gif" : flag = this.option["image"]; break;
|
||||
case "mp3" : case "wav" : case "ram" : case "wma" : flag = this.option["sound"]; break;
|
||||
case "mpg" : case "mpeg" : case "avi" :
|
||||
case "ram" : case "rm" : case "mov" : case "wmv" : flag = this.option["movie"]; break;
|
||||
case "zip" : case "lzh" : case "rar" : case "xpi" : flag = this.option["archive"]; break;
|
||||
switch (ext) {
|
||||
case "jpg":
|
||||
case "jpeg":
|
||||
case "png":
|
||||
case "gif":
|
||||
flag = this.option["image"];
|
||||
break;
|
||||
case "mp3":
|
||||
case "wav":
|
||||
case "ram":
|
||||
case "wma":
|
||||
flag = this.option["sound"];
|
||||
break;
|
||||
case "mpg":
|
||||
case "mpeg":
|
||||
case "avi":
|
||||
case "ram":
|
||||
case "rm":
|
||||
case "mov":
|
||||
case "wmv":
|
||||
flag = this.option["movie"];
|
||||
break;
|
||||
case "zip":
|
||||
case "lzh":
|
||||
case "rar":
|
||||
case "xpi":
|
||||
flag = this.option["archive"];
|
||||
break;
|
||||
default:
|
||||
if (ext && this.option["custom"]) {
|
||||
if ((", " + this.option["custom"] + ", ").indexOf(", " + ext + ", ") != -1) flag = true;
|
||||
|
@ -272,8 +285,7 @@ var wpdDOMSaver = {
|
|||
|
||||
|
||||
// do the conversion from the DOM Text to the destination Charset
|
||||
convertEntity : function(aText)
|
||||
{
|
||||
convertEntity: function (aText) {
|
||||
if (this.option["encodeUTF8"]) {
|
||||
return wpdCommon.unicodeToEntity(aText, "UTF-8");
|
||||
} else {
|
||||
|
@ -282,8 +294,7 @@ var wpdDOMSaver = {
|
|||
},
|
||||
|
||||
// we only can manage GIF animations - Flash does not work...
|
||||
disableAnimation : function(aNode)
|
||||
{
|
||||
disableAnimation: function (aNode) {
|
||||
// thanx to pageanimator extension...
|
||||
/* try {
|
||||
//dump("inspecting "+aNode.nodeName+"\n");
|
||||
|
@ -305,8 +316,7 @@ var wpdDOMSaver = {
|
|||
},
|
||||
|
||||
// get the node value of aNode directly from the actual DOM tree (WPD_CLONENODEBUG)
|
||||
getCurrentNodeValue : function(aNode)
|
||||
{
|
||||
getCurrentNodeValue: function (aNode) {
|
||||
try {
|
||||
this.curDocument.body.cloneNode(false);
|
||||
var body = this.curDocument.body;
|
||||
|
@ -317,9 +327,7 @@ var wpdDOMSaver = {
|
|||
var nodes = this.curBody.getElementsByTagName(aNode.nodeName);
|
||||
if (refnodes.length != nodes.length) return aNode.value;
|
||||
for (var i = 0; i < refnodes.length; i++) {
|
||||
if ( ( nodes[i]==aNode ) &&
|
||||
( refnodes[i].name==aNode.name ) &&
|
||||
( refnodes[i].defaultValue==aNode.defaultValue ) ) {
|
||||
if ((nodes[i] == aNode) && (refnodes[i].name == aNode.name) && (refnodes[i].defaultValue == aNode.defaultValue)) {
|
||||
return refnodes[i].value;
|
||||
}
|
||||
}
|
||||
|
@ -327,14 +335,13 @@ var wpdDOMSaver = {
|
|||
},
|
||||
|
||||
// process the DOM Node (update the links, remove attributes and process the options)
|
||||
processDOMNode : function(aNode)
|
||||
{
|
||||
processDOMNode: function (aNode) {
|
||||
this.disableAnimation(aNode);
|
||||
try {
|
||||
switch ( aNode.nodeName.toLowerCase() )
|
||||
{
|
||||
switch (aNode.nodeName.toLowerCase()) {
|
||||
case "img":
|
||||
case "embed" : // "embed": embedding multimedia content
|
||||
case "embed":
|
||||
// "embed": embedding multimedia content
|
||||
if (this.option["format"]) {
|
||||
if (aNode.hasAttribute("onclick")) aNode = this.normalizeJavaScriptLink(aNode, "onclick");
|
||||
var aDownload = true;
|
||||
|
@ -350,7 +357,8 @@ var wpdDOMSaver = {
|
|||
return wpdCommon.removeNodeFromParent(aNode);
|
||||
}
|
||||
break;
|
||||
case "object" : // for embedding different data sources in the html page
|
||||
case "object":
|
||||
// for embedding different data sources in the html page
|
||||
if (this.option["format"]) {
|
||||
var aFileName = this.download(aNode.data, true);
|
||||
// Changed by Dan S. for Zotero -- see this.repairRelativeLinks()
|
||||
|
@ -398,7 +406,8 @@ var wpdDOMSaver = {
|
|||
if (WPD_ENTITYBUG) aNode.setAttribute("value", this.convertEntity(aNode.getAttribute("value")));
|
||||
}
|
||||
break;
|
||||
case "link" : // could containt urls (icon, stylesheet and fontdef)
|
||||
case "link":
|
||||
// could containt urls (icon, stylesheet and fontdef)
|
||||
// We have to remove nodes with the stylesheet attribute because they will be added later
|
||||
if ((aNode.getAttribute("rel").toLowerCase() == "stylesheet") && (aNode.getAttribute("href").indexOf("chrome://") == -1)) {
|
||||
return wpdCommon.removeNodeFromParent(aNode);
|
||||
|
@ -442,8 +451,7 @@ var wpdDOMSaver = {
|
|||
}
|
||||
break;
|
||||
case "noscript":
|
||||
if ( !WPD_JAVASCRIPTSRCBUG )
|
||||
return wpdCommon.removeNodeFromParent(aNode);
|
||||
if (!WPD_JAVASCRIPTSRCBUG) return wpdCommon.removeNodeFromParent(aNode);
|
||||
break;
|
||||
case "a":
|
||||
case "area":
|
||||
|
@ -464,17 +472,11 @@ var wpdDOMSaver = {
|
|||
aNode.setAttribute("action", wpdCommon.resolveURL(this.currentURL, aNode.action));
|
||||
break;
|
||||
case "meta":
|
||||
if ( (aNode.hasAttribute("http-equiv") && aNode.hasAttribute("content")) &&
|
||||
(aNode.getAttribute("http-equiv").toLowerCase() == "content-type") &&
|
||||
(aNode.getAttribute("content").match(/charset\=/i)) )
|
||||
{
|
||||
if ((aNode.hasAttribute("http-equiv") && aNode.hasAttribute("content")) && (aNode.getAttribute("http-equiv").toLowerCase() == "content-type") && (aNode.getAttribute("content").match(/charset\=/i))) {
|
||||
// we remove possible charset definitions because they will be added later
|
||||
return wpdCommon.removeNodeFromParent(aNode);
|
||||
}
|
||||
if ( (aNode.hasAttribute("http-equiv") && aNode.hasAttribute("content")) &&
|
||||
(aNode.getAttribute("http-equiv").toLowerCase() == "refresh") &&
|
||||
(aNode.getAttribute("content").match(/URL\=/i)) )
|
||||
{
|
||||
if ((aNode.hasAttribute("http-equiv") && aNode.hasAttribute("content")) && (aNode.getAttribute("http-equiv").toLowerCase() == "refresh") && (aNode.getAttribute("content").match(/URL\=/i))) {
|
||||
// there should be no refresh present - could be a noframe relict...
|
||||
// (is already processed or timer is longer...)
|
||||
return wpdCommon.removeNodeFromParent(aNode);
|
||||
|
@ -483,12 +485,12 @@ var wpdDOMSaver = {
|
|||
case "base":
|
||||
//<BASE HREF="http://www.amin.org/look/amin/">
|
||||
// we need to set the base url to currenturl
|
||||
if ( aNode.hasAttribute("href") && (aNode.getAttribute("href")!="") )
|
||||
this.currentURL=aNode.getAttribute("href");
|
||||
if (aNode.hasAttribute("href") && (aNode.getAttribute("href") != "")) this.currentURL = aNode.getAttribute("href");
|
||||
return wpdCommon.removeNodeFromParent(aNode);
|
||||
break;
|
||||
case "frame":
|
||||
case "iframe" : // normal and embedded frames (iframe) -> call "saveDocumentEx" for saving the frame document
|
||||
case "iframe":
|
||||
// normal and embedded frames (iframe) -> call "saveDocumentEx" for saving the frame document
|
||||
try {
|
||||
// we don't have to worry about the currentURL - saveDocumentEx will set the
|
||||
// currentURL to the URL of the frame document and afterwards back to the baseURL
|
||||
|
@ -526,11 +528,9 @@ var wpdDOMSaver = {
|
|||
|
||||
|
||||
// get through the DOM tree (recursiv function)
|
||||
processDOMRecursively : function(rootNode)
|
||||
{
|
||||
processDOMRecursively: function (rootNode) {
|
||||
if (rootNode == null) return;
|
||||
for ( var curNode = rootNode.firstChild; curNode != null; curNode = curNode.nextSibling )
|
||||
{
|
||||
for (var curNode = rootNode.firstChild; curNode != null; curNode = curNode.nextSibling) {
|
||||
if (curNode.nodeName != "#text" && curNode.nodeName != "#comment") {
|
||||
curNode = this.processDOMNode(curNode);
|
||||
this.processDOMRecursively(curNode);
|
||||
|
@ -549,8 +549,7 @@ var wpdDOMSaver = {
|
|||
// style attribute does not work - innerHTML will finally
|
||||
// generate e.g "repeat scroll 0%;" regardless of the style setting
|
||||
// (e.g. "repeat;")
|
||||
repairInlineCSS : function(aHTMLText)
|
||||
{
|
||||
repairInlineCSS: function (aHTMLText) {
|
||||
if ((WPD_CSSSCROLLBUG) && (aHTMLText.match(/background:/i))) {
|
||||
// Regex fixed by Dan for Zotero
|
||||
//var re = new RegExp(/style=\"(.*)background:(.*)(repeat scroll 0(?:pt|px|%);)/);
|
||||
|
@ -576,8 +575,7 @@ var wpdDOMSaver = {
|
|||
},
|
||||
|
||||
|
||||
relativeLinkFix : function(aFileName)
|
||||
{
|
||||
relativeLinkFix: function (aFileName) {
|
||||
return "about:blank?" + aFileName;
|
||||
},
|
||||
|
||||
|
@ -585,15 +583,13 @@ var wpdDOMSaver = {
|
|||
// which are prepended with "about:blank?" to fix a bug in Scrapbook/WPD
|
||||
// that sending an invalid request to the server when the img src
|
||||
// is a relative link to a file in a different directory
|
||||
repairRelativeLinks : function(aHTMLText)
|
||||
{
|
||||
repairRelativeLinks: function (aHTMLText) {
|
||||
return aHTMLText.replace(/(src)="about:blank\?([^"]*)"/g, '$1="$2"');
|
||||
},
|
||||
|
||||
|
||||
// process the CSS text of one stylesheet element
|
||||
processCSSText : function(aCSStext, aCSShref, inline)
|
||||
{
|
||||
processCSSText: function (aCSStext, aCSShref, inline) {
|
||||
if (!aCSStext) return "";
|
||||
|
||||
// search for "url" entries inside the css
|
||||
|
@ -616,10 +612,8 @@ var wpdDOMSaver = {
|
|||
}
|
||||
|
||||
//
|
||||
if ( (WPD_CSSSCROLLBUG) && ( aCSStext.match(/background: /i)) )
|
||||
aCSStext = aCSStext.replace(/ scroll 0(pt|px|%);/g, ";");
|
||||
if ( (WPD_CSSBACKGROUNDPOSITIONBUG) && ( aCSStext.match(/background-position: /i)) )
|
||||
aCSStext = aCSStext.replace(/ background-position: 0(pt|px|%);/g, ";");
|
||||
if ((WPD_CSSSCROLLBUG) && (aCSStext.match(/background: /i))) aCSStext = aCSStext.replace(/ scroll 0(pt|px|%);/g, ";");
|
||||
if ((WPD_CSSBACKGROUNDPOSITIONBUG) && (aCSStext.match(/background-position: /i))) aCSStext = aCSStext.replace(/ background-position: 0(pt|px|%);/g, ";");
|
||||
return aCSStext;
|
||||
},
|
||||
|
||||
|
@ -632,8 +626,7 @@ var wpdDOMSaver = {
|
|||
// MEDIA_RULE = 4,
|
||||
// FONT_FACE_RULE = 5,
|
||||
// PAGE_RULE = 6
|
||||
processCSSRecursively : function(aCSS)
|
||||
{
|
||||
processCSSRecursively: function (aCSS) {
|
||||
if (aCSS.disabled) return "";
|
||||
var content = "";
|
||||
var medium = aCSS.media.mediaText;
|
||||
|
@ -649,10 +642,8 @@ var wpdDOMSaver = {
|
|||
// element appears within <body> instead of <head>
|
||||
try {
|
||||
aCSS.cssRules
|
||||
}
|
||||
catch (e) {
|
||||
var msg = "Unable to access cssRules property of " + aCSS.href
|
||||
+ " in wpdDOMSaver.processCSSRecursively()";
|
||||
} catch (e) {
|
||||
var msg = "Unable to access cssRules property of " + aCSS.href + " in wpdDOMSaver.processCSSRecursively()";
|
||||
Zotero.debug("WebPageDump: " + msg, 2);
|
||||
Components.utils.reportError(msg);
|
||||
return "";
|
||||
|
@ -674,31 +665,51 @@ var wpdDOMSaver = {
|
|||
return content;
|
||||
},
|
||||
|
||||
//given a file name and source URL (optional) with content (optional)
|
||||
//returns a unique file name and registers it
|
||||
getUniqueFileNameAndRegister: function(fileName, sourceURL, content) {
|
||||
fileName = this.checkForEqualFilenames(
|
||||
wpdCommon.getValidFileName(fileName).toLowerCase(),
|
||||
sourceURL);
|
||||
this.registerFile(fileName, sourceURL, content);
|
||||
return fileName;
|
||||
},
|
||||
|
||||
//register filename, so we don't overwrite them later
|
||||
registerFile: function (newFileName, sourceURL, content) {
|
||||
this.fileInfo[newFileName] = {
|
||||
url: sourceURL,
|
||||
downloaded: content
|
||||
}
|
||||
},
|
||||
|
||||
// is the file registered (e.g. downloaded)?
|
||||
isFileRegistered : function(newFileName)
|
||||
{
|
||||
if ( this.fileInfo[newFileName] != undefined )
|
||||
return true;
|
||||
isFileRegistered: function (newFileName) {
|
||||
if (this.fileInfo[newFileName] != undefined) return true;
|
||||
return false;
|
||||
},
|
||||
|
||||
isDownloaded: function(fileName) {
|
||||
if(!this.fileInfo[fileName]) return;
|
||||
return this.fileInfo[fileName].downloaded;
|
||||
},
|
||||
|
||||
// check for equal Filenames with different locations
|
||||
// if this is the case, we generate a new name...
|
||||
checkForEqualFilenames : function(newFileName,aURLSpec)
|
||||
{
|
||||
// if this is the case, we generate a new name
|
||||
// if no aURLSpec is passed, this generates a unique file name
|
||||
checkForEqualFilenames: function (newFileName, aURLSpec) {
|
||||
if (this.isFileRegistered(newFileName)) {
|
||||
if (this.fileInfo[newFileName]["url"] != aURLSpec ) {
|
||||
if (!aURLSpec || this.fileInfo[newFileName]["url"] != aURLSpec) {
|
||||
// the file is already registered but from a different location
|
||||
// => probably not the same file, so we have to find a different name it (e.g. filename_001.ext)
|
||||
var seq = 1;
|
||||
var fileLR = wpdCommon.splitFileName(newFileName);
|
||||
if (!fileLR[1]) fileLR[1] = "dat";
|
||||
while ( this.fileInfo[newFileName] != undefined )
|
||||
{
|
||||
newFileName = fileLR[0] + "_" + wpdCommon.addLeftZeros(seq++, 3) + "." + fileLR[1];
|
||||
while (this.fileInfo[newFileName] != undefined) {
|
||||
// is the file already registered with the new name?
|
||||
if ( this.fileInfo[newFileName]["url"] == aURLSpec )
|
||||
return newFileName; // Yes -> so it<69>s already downloaded and we are finished
|
||||
newFileName = fileLR[0] + "_" + wpdCommon.addLeftZeros(++seq,3) + "." + fileLR[1]; // No -> "increment" filename
|
||||
if (aURLSpec && this.fileInfo[newFileName]["url"] == aURLSpec) return newFileName; // Yes -> so it<69>s already downloaded and we are finished
|
||||
newFileName = fileLR[0] + "_" + wpdCommon.addLeftZeros(seq++, 3) + "." + fileLR[1]; // No -> "increment" filename
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -707,13 +718,11 @@ var wpdDOMSaver = {
|
|||
|
||||
// Download the specified URL to "this.currentDir". Takes
|
||||
// care about equal filenames from different locations
|
||||
download : function(aURLSpec,aDownload)
|
||||
{
|
||||
download: function (aURLSpec, aDownload) {
|
||||
if (!aURLSpec) return "";
|
||||
|
||||
// is this a relative URL (no protocol present) which needs to be resolved?
|
||||
if ( aURLSpec.indexOf("://") < 0 )
|
||||
aURLSpec = wpdCommon.resolveURL(this.currentURL, aURLSpec);
|
||||
if (aURLSpec.indexOf("://") < 0) aURLSpec = wpdCommon.resolveURL(this.currentURL, aURLSpec);
|
||||
|
||||
try {
|
||||
var aURL = wpdCommon.convertURLToObject(aURLSpec);
|
||||
|
@ -723,16 +732,15 @@ var wpdDOMSaver = {
|
|||
if (!newFileName) newFileName = "untitled";
|
||||
newFileName = wpdCommon.getValidFileName(newFileName);
|
||||
// same name but different location?
|
||||
newFileName = this.checkForEqualFilenames(newFileName,aURLSpec);
|
||||
|
||||
newFileName = this.getUniqueFileNameAndRegister(newFileName, aURLSpec);
|
||||
// is the file already registered (processed) ?
|
||||
if ( this.isFileRegistered(newFileName)==false ) {
|
||||
// No -> we have to download and register the file
|
||||
this.fileInfo[newFileName] = new Array("url","downloaded");
|
||||
this.fileInfo[newFileName]["url"] = aURLSpec;
|
||||
this.fileInfo[newFileName]["downloaded"] = true;
|
||||
if (aDownload)
|
||||
this.fileInfo[newFileName]["downloaded"] = wpdCommon.downloadFile(aURLSpec,this.currentDir+newFileName);
|
||||
if (!this.isDownloaded(newFileName)) {
|
||||
if (aDownload) {
|
||||
aDownload = wpdCommon.downloadFile(aURLSpec, this.currentDir + newFileName);
|
||||
} else {
|
||||
aDownload = true;
|
||||
}
|
||||
this.registerFile(newFileName, aURLSpec, aDownload);
|
||||
}
|
||||
return newFileName;
|
||||
} catch (ex) {
|
||||
|
@ -742,14 +750,13 @@ var wpdDOMSaver = {
|
|||
},
|
||||
|
||||
// Get a CSS filename node for inserting in the DOM Tree
|
||||
createCSSFileNode : function(aDocument,rootNode,aFileName)
|
||||
{
|
||||
createCSSFileNode: function (aDocument, rootNode, aFileName) {
|
||||
var newLinkNode = aDocument.createElement("link");
|
||||
|
||||
rootNode.firstChild.appendChild(aDocument.createTextNode("\n"));
|
||||
|
||||
newLinkNode.setAttribute("media", "all");
|
||||
newLinkNode.setAttribute("href", aFileName + ".css");
|
||||
newLinkNode.setAttribute("href", aFileName);
|
||||
newLinkNode.setAttribute("type", "text/css");
|
||||
newLinkNode.setAttribute("rel", "stylesheet");
|
||||
|
||||
|
@ -760,8 +767,7 @@ var wpdDOMSaver = {
|
|||
},
|
||||
|
||||
// Creates a placeholder node for inserting the DOCTYPE after the html tag
|
||||
createPseudeDocTypeNode : function(aDocument,rootNode)
|
||||
{
|
||||
createPseudeDocTypeNode: function (aDocument, rootNode) {
|
||||
var aDoctype = aDocument.doctype;
|
||||
if (!aDoctype) return;
|
||||
try {
|
||||
|
@ -777,8 +783,7 @@ var wpdDOMSaver = {
|
|||
},
|
||||
|
||||
// replaces the placeholder node generated by createPseudeDocTypeNode with the DOCTYPE
|
||||
replaceDocType : function(aDocument,aHTMLText)
|
||||
{
|
||||
replaceDocType: function (aDocument, aHTMLText) {
|
||||
var aDoctype = aDocument.doctype;
|
||||
if (!aDoctype) return aHTMLText;
|
||||
try {
|
||||
|
@ -791,8 +796,7 @@ var wpdDOMSaver = {
|
|||
|
||||
// Returns the HTML Text generated from rootNode and does
|
||||
// some processing (WPD_DOCTYPEBUG, WPD_ENTITYBUG, cleaning,...)
|
||||
generateHTMLString : function(aDocument,rootNode)
|
||||
{
|
||||
generateHTMLString: function (aDocument, rootNode) {
|
||||
if (WPD_DOCTYPEBUG) this.createPseudeDocTypeNode(aDocument, rootNode);
|
||||
var HTMLText = wpdCommon.nodeToHTMLString(rootNode);
|
||||
if (WPD_DOCTYPEBUG) HTMLText = this.replaceDocType(aDocument, HTMLText);
|
||||
|
@ -810,8 +814,7 @@ var wpdDOMSaver = {
|
|||
},
|
||||
|
||||
// Returns a DOCTYPE definition string based on aDocument.doctype
|
||||
getDocType : function(aDocument)
|
||||
{
|
||||
getDocType: function (aDocument) {
|
||||
var aDoctype = aDocument.doctype;
|
||||
if (!aDoctype) return "";
|
||||
var dt = "<!DOCTYPE " + aDoctype.name;
|
||||
|
@ -822,8 +825,7 @@ var wpdDOMSaver = {
|
|||
},
|
||||
|
||||
// Get the meta charset information from the document
|
||||
getMetaCharset : function(aDocument)
|
||||
{
|
||||
getMetaCharset: function (aDocument) {
|
||||
var metas = aDocument.getElementsByTagName("meta");
|
||||
for (var i = metas.length; --i >= 0;) {
|
||||
var meta = metas[i];
|
||||
|
@ -837,8 +839,7 @@ var wpdDOMSaver = {
|
|||
|
||||
|
||||
// Create and return a meta charset node for the DOM Tree
|
||||
createMetaCharsetNode : function(aDocument,rootNode,aContentType,aCharSet)
|
||||
{
|
||||
createMetaCharsetNode: function (aDocument, rootNode, aContentType, aCharSet) {
|
||||
try {
|
||||
var metaNode = aDocument.createElement("meta");
|
||||
rootNode.firstChild.insertBefore(aDocument.createTextNode("\n"), rootNode.firstChild.firstChild);
|
||||
|
@ -855,8 +856,7 @@ var wpdDOMSaver = {
|
|||
},
|
||||
|
||||
// get a meta node for the DOM Tree
|
||||
createMetaNameNode : function(aDocument,rootNode,name,content)
|
||||
{
|
||||
createMetaNameNode: function (aDocument, rootNode, name, content) {
|
||||
try {
|
||||
var metaNode = aDocument.createElement("meta");
|
||||
|
||||
|
@ -884,8 +884,7 @@ var wpdDOMSaver = {
|
|||
|
||||
|
||||
// Return the WPD Meta Base URL Information from aFile
|
||||
getMetaBaseURL : function(aFile)
|
||||
{
|
||||
getMetaBaseURL: function (aFile) {
|
||||
if (wpdCommon.pathExists(aFile)) {
|
||||
str = new String(wpdCommon.readFile(aFile, false, true));
|
||||
re = new RegExp(/<meta name=\"wpd_baseurl\" content=\"(.*?)\">/);
|
||||
|
@ -897,8 +896,7 @@ var wpdDOMSaver = {
|
|||
},
|
||||
|
||||
// Return the WPD Meta Date Information from aFile
|
||||
getMetaDate : function(aFile)
|
||||
{
|
||||
getMetaDate: function (aFile) {
|
||||
if (wpdCommon.pathExists(aFile)) {
|
||||
str = new String(wpdCommon.readFile(aFile, false, true));
|
||||
re = new RegExp(/<meta name=\"wpd_date\" content=\"(.*?)\">/);
|
||||
|
@ -910,8 +908,7 @@ var wpdDOMSaver = {
|
|||
},
|
||||
|
||||
// creates the meta nodes for the wpd meta tags (version, baseurl, url, date/time)
|
||||
createMetaInformation : function(aDocument,rootNode)
|
||||
{
|
||||
createMetaInformation: function (aDocument, rootNode) {
|
||||
// insert url/date/time meta information
|
||||
//
|
||||
var d = this.dateObj.getUTCFullYear() + "-" + wpdCommon.addLeftZeros(this.dateObj.getUTCMonth(), 2) + "-" + wpdCommon.addLeftZeros(this.dateObj.getUTCDate(), 2);
|
||||
|
@ -926,11 +923,12 @@ var wpdDOMSaver = {
|
|||
// save a non HTML "aDocument" as "aFileName" and generate a
|
||||
// wrapper HTML File which references "aDocument"
|
||||
// ("aFileName" is the filename without(!) extension)
|
||||
saveDocumentFile : function(aDocument,aFileName)
|
||||
{
|
||||
Zotero.debug("[wpdDOMSaver.saveDocumentFile]: "+aFileName);
|
||||
saveDocumentFile: function (aDocument, aFileName) {
|
||||
Zotero.debug("[wpdDOMSaver.saveDocumentFile]: Saving file from " + this.currentURL);
|
||||
aFileName = this.download(this.currentURL, true)
|
||||
Zotero.debug("[wpdDOMSaver.saveDocumentFile]: Saved to " + aFileName);
|
||||
|
||||
return this.download(this.currentURL,true)
|
||||
return aFileName;
|
||||
/* Wrapper file disabled by Dan S. for Zotero
|
||||
var aFileURL = aDocument.location.href;
|
||||
|
||||
|
@ -957,8 +955,7 @@ var wpdDOMSaver = {
|
|||
// process the CSS Text
|
||||
// "aFileName" is the filename without(!) extension
|
||||
// (".css" will be added)
|
||||
saveDocumentCSS: function(aDocument,aFileName)
|
||||
{
|
||||
saveDocumentCSS: function (aDocument, aFileName) {
|
||||
var CSSText = ""; //"body {display: block;margin: 8px;}; ";
|
||||
if (this.option["format"]) {
|
||||
var myStyleSheets = aDocument.styleSheets;
|
||||
|
@ -973,12 +970,12 @@ var wpdDOMSaver = {
|
|||
} else {
|
||||
CSSText = wpdCommon.ConvertFromUnicode16(CSSText, this.curCharacterSet);
|
||||
}
|
||||
Zotero.debug("[wpdDOMSaver.saveDocumentCSS]: "+this.currentDir+aFileName+".css");
|
||||
aFileName = this.getUniqueFileNameAndRegister(aFileName + ".css");
|
||||
Zotero.debug("[wpdDOMSaver.saveDocumentCSS]: " + this.currentDir + aFileName);
|
||||
// write css file
|
||||
var CSSFile = this.currentDir + aFileName + ".css";
|
||||
if (!wpdCommon.writeFile(CSSText, CSSFile))
|
||||
wpdCommon.addError("[wpdDOMSaver.saveDocumentCSS]: could not write CSS File\n");
|
||||
return true;
|
||||
var CSSFile = this.currentDir + aFileName;
|
||||
if (!wpdCommon.writeFile(CSSText, CSSFile)) wpdCommon.addError("[wpdDOMSaver.saveDocumentCSS]: could not write CSS File\n");
|
||||
return aFileName;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -988,9 +985,12 @@ var wpdDOMSaver = {
|
|||
// DOM Tree (see processDOMNode) - calls also saveDocumentCSS
|
||||
// "aFileName" is the filename without(!) extension
|
||||
// (".html" will be added)
|
||||
saveDocumentHTML: function(aDocument,aFileName)
|
||||
{
|
||||
Zotero.debug("[wpdDOMSaver.saveDocumentHTML]: "+this.currentDir+aFileName+".html");
|
||||
saveDocumentHTML: function (aDocument, aFileName) {
|
||||
aFileName = this.getUniqueFileNameAndRegister(aFileName + ".html");
|
||||
var aFileNameNoExt = wpdCommon.splitFileName(aFileName)[0];
|
||||
|
||||
Zotero.debug("[wpdDOMSaver.saveDocumentHTML]: " + this.currentDir + aFileName);
|
||||
|
||||
this.curDocument = aDocument;
|
||||
this.curCharacterSet = aDocument.characterSet;
|
||||
var charset = this.curCharacterSet;
|
||||
|
@ -1015,12 +1015,11 @@ var wpdDOMSaver = {
|
|||
this.processDOMRecursively(rootNode);
|
||||
|
||||
// write css file and add css node with the new css filename in the DOM Tree
|
||||
if (this.saveDocumentCSS(aDocument,aFileName))
|
||||
this.createCSSFileNode(aDocument,rootNode,aFileName);
|
||||
var cssFileName = this.saveDocumentCSS(aDocument, aFileNameNoExt);
|
||||
if (cssFileName) this.createCSSFileNode(aDocument, rootNode, cssFileName);
|
||||
|
||||
// create meta information (version, base_url, url, date/time)
|
||||
if (this.option["metainfo"])
|
||||
this.createMetaInformation(aDocument,rootNode);
|
||||
if (this.option["metainfo"]) this.createMetaInformation(aDocument, rootNode);
|
||||
|
||||
// add the charset defintions previously removed by processDOMNode
|
||||
if (this.option["encodeUTF8"]) {
|
||||
|
@ -1034,7 +1033,6 @@ var wpdDOMSaver = {
|
|||
|
||||
// "var " added by Dan S. for Zotero
|
||||
var HTMLText = this.generateHTMLString(aDocument, rootNode);
|
||||
|
||||
// convert the DOM String to the desired Charset
|
||||
if (this.option["encodeUTF8"]) {
|
||||
HTMLText = wpdCommon.ConvertFromUnicode16(HTMLText, "UTF-8");
|
||||
|
@ -1045,16 +1043,14 @@ var wpdDOMSaver = {
|
|||
this.curCharacterSet = charset;
|
||||
|
||||
// and write the file...
|
||||
var HTMLFile = this.currentDir + aFileName + ".html";
|
||||
if (!wpdCommon.writeFile(HTMLText, HTMLFile))
|
||||
wpdCommon.addError("[wpdDOMSaver.saveDocumentHTML]: could not write HTML File\n");
|
||||
var HTMLFile = this.currentDir + aFileName;
|
||||
if (!wpdCommon.writeFile(HTMLText, HTMLFile)) wpdCommon.addError("[wpdDOMSaver.saveDocumentHTML]: could not write HTML File\n");
|
||||
|
||||
return aFileName + ".html";
|
||||
return aFileName;
|
||||
},
|
||||
|
||||
// Decides the calling of SaveDocumentFile or saveDocumentHTML
|
||||
saveDocumentEx : function(aDocument,aFileName)
|
||||
{
|
||||
saveDocumentEx: function (aDocument, aFileName) {
|
||||
// we have to set a new current url which is the
|
||||
// base reference url (necessary for frame processing)
|
||||
this.currentURL = aDocument.location.href;
|
||||
|
@ -1076,8 +1072,7 @@ var wpdDOMSaver = {
|
|||
|
||||
// Main Routine: call it for saving the actual active top window
|
||||
// (be sure to call the init function at the top of this file before)
|
||||
saveHTMLDocument: function()
|
||||
{
|
||||
saveHTMLDocument: function () {
|
||||
try {
|
||||
this.saveDocumentEx(this.document, this.name);
|
||||
} catch (ex) {
|
||||
|
|
|
@ -819,6 +819,11 @@ function ChromeExtensionHandler() {
|
|||
var fileURI = ph.newFileURI(file);
|
||||
}
|
||||
var channel = ioService.newChannelFromURI(fileURI);
|
||||
//set originalURI so that it seems like we're serving from zotero:// protocol
|
||||
//this is necessary to allow url() links to work from within css files
|
||||
//otherwise they try to link to files on the file:// protocol, which is not allowed
|
||||
channel.originalURI = uri;
|
||||
|
||||
return channel;
|
||||
}
|
||||
catch (e) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user