Skip to content

Commit

Permalink
now handles unencoding properly fixes #27
Browse files Browse the repository at this point in the history
  • Loading branch information
buggyj committed Nov 26, 2017
1 parent 9216796 commit 7715e61
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions extension/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7715e61

Please sign in to comment.