diff --git a/extension/contentscript.js b/extension/contentscript.js index d43ab62..8608b8d 100644 --- a/extension/contentscript.js +++ b/extension/contentscript.js @@ -15,7 +15,35 @@ var tw5 = true; * if it lands in the correct dir, * the backgound would set a value we read here and if set save a test file. */ - + +function currentlocation() { + // Get the pathname of this document + var pathname = window.location.toString().split("#")[0]; + // Replace file://localhost/ with file:/// + if(pathname.indexOf("file://localhost/") === 0) { + pathname = "file://" +pathname.substr(16); + } + // Windows path file:///x:/blah/blah --> x:\blah\blah + if(/^file\:\/\/\/[A-Z]\:\//i.test(pathname)) { + // Remove the leading slash and convert slashes to backslashes + pathname = decodeURI(pathname.substr(8)).replace(/\//g,"\\"); + // Firefox Windows network path file://///server/share/blah/blah --> //server/share/blah/blah + } else if(pathname.indexOf("file://///") === 0) { + pathname = "\\\\" + decodeURI(pathname.substr(10)).replace(/\//g,"\\"); + // Mac/Unix local path file:///path/path --> /path/path + } else if(pathname.indexOf("file:///") === 0) { + pathname = decodeURI(pathname.substr(7)); + // Mac/Unix local path file:/path/path --> /path/path + } else if(pathname.indexOf("file:/") === 0) { + pathname = decodeURI(pathname.substr(5)); + // Otherwise Windows networth path file://server/share/path/path --> \\server\share\path\path + } else { + pathname = "\\\\" + decodeURI(pathname.substr(7)).replace(new RegExp("/","g"),"\\"); + } + + return pathname; + } + function isTiddlyWikiClassic(doc) { // Test whether the document is a TiddlyWiki (we don't have access to JS objects in it) var versionArea = doc.getElementById("versionArea"); @@ -61,8 +89,7 @@ function injectMessageBox(doc) { var message = event.target, path, content = message.getAttribute("data-tiddlyfox-content"); - try{path = decodeURI(escape(message.getAttribute("data-tiddlyfox-path")))} //unescape was used insted of decodeURI - catch(e){path = message.getAttribute("data-tiddlyfox-path")}; // in case this get fixed + path = currentlocation(); // Remove the message element from the message box message.parentNode.removeChild(message); // Save the file