1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-08 13:04:21 +00:00
TiddlyWiki5/tiddlyfox/extension/content/inject.js
Jeremy Ruston 2a56c043d7 Basic, dumb saving in TiddlyFox now works
It seems to work OK, but could do with more of a user interface for
confirmations and so on...
2012-08-27 21:48:57 +01:00

45 lines
1.2 KiB
JavaScript

/*
The JavaScript in this file is injected into each TiddlyWiki page that loads
*/
(function () {
/*
Returns true if successful, false if failed, null if not available
*/
var injectedSaveFile = function(path,content) {
// Find the message box element
var messageBox = document.getElementById("tiddlyfox-message-box");
if(messageBox) {
// Create the message element and put it in the message box
var message = document.createElement("div");
message.setAttribute("tiddlyfox-path",path);
message.setAttribute("tiddlyfox-content",content);
messageBox.appendChild(message);
// Create and dispatch the custom event to the extension
var event = document.createEvent("Events");
event.initEvent("tiddlyfox-save-file",true,false);
message.dispatchEvent(event);
}
return true;
};
/*
Returns text if successful, false if failed, null if not available
*/
var injectedLoadFile = function(path) {
try {
// Just the read the file synchronously
var xhReq = new XMLHttpRequest();
xhReq.open("GET", "file://" + path, false);
xhReq.send(null);
return xhReq.responseText;
} catch(ex) {
return false;
}
};
window.mozillaSaveFile = injectedSaveFile;
window.mozillaLoadFile = injectedLoadFile;
})();