1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-11-01 08:03:00 +00:00

BrowserStorage: A new plugin to save tiddlers to local storage

Experimental at this point.
This commit is contained in:
Jermolene
2019-02-03 12:51:15 +00:00
parent 70f5dff81e
commit e31c5563ff
6 changed files with 137 additions and 1 deletions

View File

@@ -0,0 +1,41 @@
/*\
title: $:/plugins/tiddlywiki/browser-storage/startup.js
type: application/javascript
module-type: startup
Startup initialisation
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
// Export name and synchronous status
exports.name = "browser-storage";
exports.platforms = ["browser"];
exports.after = ["load-modules"];
exports.synchronous = true;
exports.startup = function() {
// Compute our prefix for local storage keys
var url = window.location.protocol === "file:" ? window.location.pathname : "",
prefix = "tw5#" + url + "#"
// Track tiddler changes
$tw.wiki.addEventListener("change",function(changes) {
$tw.utils.each(changes,function(change,title) {
var tiddler = $tw.wiki.getTiddler(title);
if(tiddler) {
var json = JSON.stringify(tiddler.getFieldStrings());
window.localStorage.setItem(prefix + title,json);
console.log("browser-storage: Saving",title);
} else {
window.localStorage.removeItem(prefix + title);
console.log("browser-storage: Deleting",title);
}
});
});
};
})();