mirror of
https://github.com/TiddlyWiki/TiddlyWiki5.git
synced 2026-05-01 05:06:57 +00:00
Browser-storage: Add enable/disable and clear button
This commit is contained in:
@@ -18,7 +18,8 @@ exports.platforms = ["browser"];
|
||||
exports.after = ["load-modules"];
|
||||
exports.synchronous = true;
|
||||
|
||||
var SAVE_FILTER_TITLE = "$:/config/BrowserStorage/SaveFilter",
|
||||
var ENABLED_TITLE = "$:/config/BrowserStorage/Enabled",
|
||||
SAVE_FILTER_TITLE = "$:/config/BrowserStorage/SaveFilter",
|
||||
QUOTA_EXCEEDED_ALERT_TITLE = "$:/config/BrowserStorage/QuotaExceededAlert",
|
||||
DEFAULT_QUOTA_EXCEEDED_ALERT_PREFIX = "Quota exceeded attempting to store `",
|
||||
DEFAULT_QUOTA_EXCEEDED_ALERT_SUFFIX = "` in browser local storage";
|
||||
@@ -37,8 +38,17 @@ exports.startup = function() {
|
||||
filterFn = $tw.wiki.compileFilter($tw.wiki.getTiddlerText(SAVE_FILTER_TITLE));
|
||||
}
|
||||
compileFilter();
|
||||
// Listen for tm-clear-browser-storage messages
|
||||
$tw.rootWidget.addEventListener("tm-clear-browser-storage",function(event) {
|
||||
window.localStorage.clear();
|
||||
$tw.wiki.addTiddler({title: ENABLED_TITLE, text: "no"});
|
||||
});
|
||||
// Track tiddler changes
|
||||
$tw.wiki.addEventListener("change",function(changes) {
|
||||
// Bail if browser storage is disabled
|
||||
if($tw.wiki.getTiddlerText(ENABLED_TITLE) === "no") {
|
||||
return;
|
||||
}
|
||||
// Recompile the filter if it has changed
|
||||
if(changes[SAVE_FILTER_TITLE]) {
|
||||
compileFilter();
|
||||
@@ -50,8 +60,12 @@ exports.startup = function() {
|
||||
iterator(tiddler,title);
|
||||
});
|
||||
});
|
||||
console.log("Filtered changes",filteredChanges)
|
||||
$tw.utils.each(filteredChanges,function(title) {
|
||||
// Don't try to save changes to our enabled status
|
||||
// (If it were enabled in the file but disabled in local storage then we might not realise that distributing a copy of the file would have local storage enabled for other users)
|
||||
if(title === ENABLED_TITLE) {
|
||||
return;
|
||||
}
|
||||
// Get the tiddler
|
||||
var tiddler = $tw.wiki.getTiddler(title);
|
||||
if(tiddler) {
|
||||
|
||||
Reference in New Issue
Block a user