1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-27 18:40:28 +00:00
TiddlyWiki5/tiddlyfox/extension/content/inject.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

/*
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;
})();