kopia lustrzana https://github.com/miklobit/TiddlyWiki5
				
				
				
			BrowserStorage: Add startup log and fix save filter
The previous filter was rejecting tiddlers that needed to be deleted.allow-filter-duplicates
							rodzic
							
								
									adb07ccba0
								
							
						
					
					
						commit
						2c37c25c28
					
				| 
						 | 
				
			
			@ -1,2 +1,2 @@
 | 
			
		|||
title: $:/config/BrowserStorage/SaveFilter
 | 
			
		||||
text: [is[tiddler]]
 | 
			
		||||
text: [all[]]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,12 @@
 | 
			
		|||
title: $:/plugins/tiddlywiki/browser-storage/icon
 | 
			
		||||
tags: $:/tags/Image
 | 
			
		||||
 | 
			
		||||
<svg class="tc-image-down-arrow tc-image-button" viewBox="0 0 128 128" width="22pt" height="22pt">
 | 
			
		||||
    <g stroke="none" stroke-width="1" fill-rule="evenodd">
 | 
			
		||||
        <ellipse id="Oval" cx="64" cy="16" rx="40" ry="16"></ellipse>
 | 
			
		||||
        <path d="M24,96 C24,104.836556 41.90861,112 64,112 C86.09139,112 104,104.836556 104,96 L104,112 C104,120.836556 86.09139,128 64,128 C41.90861,128 24,120.836556 24,112 L24,96 Z" id="Combined-Shape"></path>
 | 
			
		||||
        <path d="M24,72 C24,80.836556 41.90861,88 64,88 C86.09139,88 104,80.836556 104,72 L104,88 C104,96.836556 86.09139,104 64,104 C41.90861,104 24,96.836556 24,88 L24,72 Z" id="Combined-Shape-Copy-16"></path>
 | 
			
		||||
        <path d="M24,48 C24,56.836556 41.90861,64 64,64 C86.09139,64 104,56.836556 104,48 L104,64 C104,72.836556 86.09139,80 64,80 C41.90861,80 24,72.836556 24,64 L24,48 Z" id="Combined-Shape-Copy-17"></path>
 | 
			
		||||
        <path d="M24,24 C24,32.836556 41.90861,40 64,40 C86.09139,40 104,32.836556 104,24 L104,40 C104,48.836556 86.09139,56 64,56 C41.90861,56 24,48.836556 24,40 L24,24 Z" id="Combined-Shape-Copy-18"></path>
 | 
			
		||||
    </g>
 | 
			
		||||
</svg>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
{
 | 
			
		||||
	"title": "$:/plugins/tiddlywiki/browser-storage",
 | 
			
		||||
	"description": "Local storage in the browser",
 | 
			
		||||
	"description": "Browser-based local storage",
 | 
			
		||||
	"author": "Jeremy Ruston ",
 | 
			
		||||
	"core-version": ">=5.0.0",
 | 
			
		||||
	"list": "readme settings"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,7 +23,8 @@ if(Object.prototype.hasOwnProperty.call($tw.hooks.names,hookName)) {
 | 
			
		|||
 | 
			
		||||
// Load tiddlers from browser storage
 | 
			
		||||
function hookBootTiddlersLoaded() {
 | 
			
		||||
	var url = window.location.protocol === "file:" ? window.location.pathname : "";
 | 
			
		||||
	var url = window.location.protocol === "file:" ? window.location.pathname : "",
 | 
			
		||||
		log = [];
 | 
			
		||||
	// Step through each browsder storage item
 | 
			
		||||
	for(var index=0; index<window.localStorage.length; index++) {
 | 
			
		||||
		var key = window.localStorage.key(index),
 | 
			
		||||
| 
						 | 
				
			
			@ -47,15 +48,19 @@ function hookBootTiddlersLoaded() {
 | 
			
		|||
						if(existingTiddler && existingTiddler.isEqual(incomingTiddler)) {
 | 
			
		||||
							// If the incoming tiddler is the same as the existing then we can delete the local storage version
 | 
			
		||||
							window.localStorage.removeItem(key);
 | 
			
		||||
							console.log("Removing from local storage",title)
 | 
			
		||||
						}
 | 
			
		||||
						$tw.wiki.addTiddler(incomingTiddler);
 | 
			
		||||
						console.log("Loading from local storage",title);
 | 
			
		||||
						log.push(title);
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	// Save the log
 | 
			
		||||
	$tw.wiki.addTiddler({
 | 
			
		||||
		title: "$:/temp/BrowserStorage/Log",
 | 
			
		||||
		text: $tw.utils.stringifyList(log)
 | 
			
		||||
	});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
})();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,19 @@
 | 
			
		|||
title: $:/plugins/tiddlywiki/browser-storage/settings
 | 
			
		||||
 | 
			
		||||
This filter determines which tiddlers will be saved to local storage. By default, it contains `[is[tiddler]]` 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.
 | 
			
		||||
! 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.
 | 
			
		||||
 | 
			
		||||
<$link to="$:/config/BrowserStorage/SaveFilter">Browser Storage Save Filter</$link>: <$edit-text tiddler="$:/config/BrowserStorage/SaveFilter" default="" tag="input" size="50"/>
 | 
			
		||||
 | 
			
		||||
! Custom Quota Exceeded Alert
 | 
			
		||||
 | 
			
		||||
This setting allows a custom alert message to be displayed when an attempt to store a tiddler fails due to the storage quota being exceeded:
 | 
			
		||||
 | 
			
		||||
<$link to="$:/config/BrowserStorage/QuotaExceededAlert">Quota Exceeded Alert</$link>: <$edit-text tiddler="$:/config/BrowserStorage/QuotaExceededAlert" default="" tag="input" size="50"/>
 | 
			
		||||
 | 
			
		||||
! Startup Log
 | 
			
		||||
 | 
			
		||||
The tiddler $:/temp/BrowserStorage/Log contains a log of the tiddlers that were loaded from local storage at startup:
 | 
			
		||||
 | 
			
		||||
<<list-links "[enlist{$:/temp/BrowserStorage/Log}sort[]]">>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue