mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +00:00
Browser-storage: Add enable/disable and clear button
This commit is contained in:
parent
655fc31cee
commit
a6875df7ef
@ -1,5 +1,17 @@
|
|||||||
title: $:/plugins/tiddlywiki/browser-storage/settings
|
title: $:/plugins/tiddlywiki/browser-storage/settings
|
||||||
|
|
||||||
|
! Disable
|
||||||
|
|
||||||
|
You can disable the browser storage plugin:
|
||||||
|
|
||||||
|
<$checkbox tiddler="$:/config/BrowserStorage/Enabled" field="text" checked="yes" unchecked="no" default="yes"> Use browser local storage</$checkbox>
|
||||||
|
|
||||||
|
! Clear
|
||||||
|
|
||||||
|
Click this button to clear browser storage and disable its use:
|
||||||
|
|
||||||
|
<$button message="tm-clear-browser-storage">Clear browser storage</$button>
|
||||||
|
|
||||||
! Save Filter
|
! Save Filter
|
||||||
|
|
||||||
This filter determines which tiddlers will be saved to local storage. By default, it contains `[all[]]` meaning that it will attempt to save all tiddlers. Other useful values include `[prefix[$:/state/]]` to just save state tiddlers, thus preserving selected tabs, and the open/closed status of table of contents entries.
|
This filter determines which tiddlers will be saved to local storage. By default, it contains `[all[]]` meaning that it will attempt to save all tiddlers. Other useful values include `[prefix[$:/state/]]` to just save state tiddlers, thus preserving selected tabs, and the open/closed status of table of contents entries.
|
||||||
|
@ -18,7 +18,8 @@ exports.platforms = ["browser"];
|
|||||||
exports.after = ["load-modules"];
|
exports.after = ["load-modules"];
|
||||||
exports.synchronous = true;
|
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",
|
QUOTA_EXCEEDED_ALERT_TITLE = "$:/config/BrowserStorage/QuotaExceededAlert",
|
||||||
DEFAULT_QUOTA_EXCEEDED_ALERT_PREFIX = "Quota exceeded attempting to store `",
|
DEFAULT_QUOTA_EXCEEDED_ALERT_PREFIX = "Quota exceeded attempting to store `",
|
||||||
DEFAULT_QUOTA_EXCEEDED_ALERT_SUFFIX = "` in browser local storage";
|
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));
|
filterFn = $tw.wiki.compileFilter($tw.wiki.getTiddlerText(SAVE_FILTER_TITLE));
|
||||||
}
|
}
|
||||||
compileFilter();
|
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
|
// Track tiddler changes
|
||||||
$tw.wiki.addEventListener("change",function(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
|
// Recompile the filter if it has changed
|
||||||
if(changes[SAVE_FILTER_TITLE]) {
|
if(changes[SAVE_FILTER_TITLE]) {
|
||||||
compileFilter();
|
compileFilter();
|
||||||
@ -50,8 +60,12 @@ exports.startup = function() {
|
|||||||
iterator(tiddler,title);
|
iterator(tiddler,title);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
console.log("Filtered changes",filteredChanges)
|
|
||||||
$tw.utils.each(filteredChanges,function(title) {
|
$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
|
// Get the tiddler
|
||||||
var tiddler = $tw.wiki.getTiddler(title);
|
var tiddler = $tw.wiki.getTiddler(title);
|
||||||
if(tiddler) {
|
if(tiddler) {
|
||||||
|
Loading…
Reference in New Issue
Block a user