1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-01-07 16:00:28 +00:00
TiddlyWiki5/tiddlyfox/extension/content/inject.js
2012-09-09 11:44:27 +01:00

50 lines
1.4 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("data-tiddlyfox-path",path);
message.setAttribute("data-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:///" + escape(path), false);
xhReq.send(null);
return xhReq.responseText;
} catch(ex) {
return false;
}
};
var injectedConvertUriToUTF8 = function(path) {
return path;
}
window.mozillaSaveFile = injectedSaveFile;
window.mozillaLoadFile = injectedLoadFile;
window.convertUriToUTF8 = injectedConvertUriToUTF8;
})();