mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-27 02:20:28 +00:00
2a56c043d7
It seems to work OK, but could do with more of a user interface for confirmations and so on...
45 lines
1.2 KiB
JavaScript
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;
|
|
|
|
})(); |