-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTiddlyStow-ZH.html
446 lines (391 loc) · 16 KB
/
TiddlyStow-ZH.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>TiddlyStow - 使用浏览器文件系统api本地存储TiddlyWiki文件</title>
<link rel="shortcut icon" type="images/x-icon" href="https://btheado.github.io/tiddlystow/favicon.ico">
<link rel="manifest" href="manifest-ZH.json">
<!-- WhiteFall新建的新的布局UI样式表 -->
<style type="text/css">
.aside {
background-color: #566d97;
color: whitesmoke;
text-align: center;
width: 150px;
min-height: 600px;
}
.container.is-vertical {
flex-direction: column;
}
.container {
display: flex;
flex-direction: row;
flex: 1;
flex-basis: auto;
box-sizing: border-box;
min-width: 0;
}
.main {
margin-left: 20px;
min-width: 470px;
}
.sub-menu-button {
width: 150px;
height: 47px;
}
</style>
</head>
<body data-version="3.4.0" data-settings-changed-at="0" data-cid="1661314345755">
<div class="container">
<aside class="aside" id="aside-000">
<div class="scrollbar">
<p class="aside-title">从远程url打开新的wiki</p>
<button class="sub-menu-button" type="button" onclick="openFromUrl('https://tiddlywiki.com/empty.html')">empty.html</button>
<button class="sub-menu-button" type="button" onclick="window.open('https://tidgi.fun/')">TidGi官网</button>
<button class="sub-menu-button" type="button" onclick="window.open('https://github.com/tiddly-gittly/TidGi-Desktop/releases')">TidGi-Github-Releases</button>
<button class="sub-menu-button" type="button" onclick="window.open('https://github.com/TiddlyWiki/TiddlyDesktop/releases')">TiddlyDesktop软件发布页</button>
<button class="sub-menu-button" type="button" onclick="window.open('https://tiddlymemo.org/manual/zh-Hans')">墨屉中文手册主页</button>
<button class="sub-menu-button" type="button" onclick="window.open('https://tw-cn.netlify.app')">太微中文教程</button>
<button class="sub-menu-button" type="button" onclick="window.open('https://tw-cpl.netlify.app/')">TW5中文社区插件源</button>
</div>
</aside>
<div class="container is-vertical">
<main class="main">
<h1>TiddlyStow</h1>
<p>这个简单的页面用于加载本地<a href="https://tiddlywiki.com/">TiddlyWiki太微</a>程序文件(一个HTML文件),并将其保存到相同的本地文件中。</p>
<p>TiddlyStow可以作为<a href="https://tw-cn.netlify.app/#开始%3A桌面端浏览器中的太微">在桌面浏览器中使用TiddlyWiki</a>的起点,你可以使用侧边栏中的模板创建TiddlyWiki文档。其它三个组件分别为<a href="https://ibnishak.github.io/Timimi/">Timimi</a>(保存与备份)、FSA Uploader(自动上传图片到本地文件夹)、kopia(定时备份);在没有任何用于保存TiddlyWiki的工具的情况下,点击TiddlyWiki中的保存变更按钮你的浏览器将下载一份更新后的TiddlyWiki。</p>
<p>你可以把创建的TiddlyWiki当做在任意位置可以阅读但只能在电脑上使用浏览器修改的Word文档使用。</p>
<ul>
<li>在这里打开任何文件之前,请确保有一个备份!</li>
<li>一定要经常备份你的文件!</li>
<li>
并不是所有的浏览器都 <a href="https://caniuse.com/native-filesystem-api">支持本地文件特性</a>.
<span id="support-message"><b>好消息!你的浏览器支持它。</b></span>
</li>
<li>可用的桌面浏览器:Edge/Chrome版本大于86,Safari版本大于15.2,Opera版本大于72。</li>
<li>创建的太微文档可以使用TidGi的导入Wiki.HTML功能导入到TidGi(太记)中使用。</li>
<li>你也可以把创建的tiddlywiki.html文档放入安卓的<a href="https://github.com/donmor/Tiddloid/releases">tiddloid</a>中使用。</li>
<li>仅适用于单个TiddlyWiki文件实例。</li>
<li>不喜欢在浏览器存储中保存最近的文件列表?点击 <a href="TiddlyStow-ZH.html#norecent">这里</a> 并刷新页面。</li>
<li><a href="https://github.com/slaymaker1907/TW5-browser-nativesaver">TW5 browser nativesaver</a>
是一个类似的项目,但有更多的功能,并捆绑为TiddlyWiki插件。</li>
<li>源代码可在 <a href="https://github.com/tiddly-gittly/TWPUB-BOOK">Github</a> 或者在浏览器中使用“查看页面源代码”。</li>
<li>加载Tiddlywiki文件后,刷新页面返回到文件选择器。</li>
<li><b><span style='color:#70AD47'>从远程URL加载新的Tiddlywiki文件,需要一点时间下载文件,请耐心等待几秒。</span></b></li>
</ul>
<p></p>
<button type="button" onclick="openFile()">从本地打开现有的文件...</button>
<div id="recent-files"></div>
</main>
</div>
</div>
<script type="module">
/* From https://github.com/jakearchibald/idb-keyval */
/* Retreived 2020-04-10 */
let idbKeyval = (function (exports) {
'use strict';
class Store {
constructor(dbName = 'keyval-store', storeName = 'keyval') {
this.storeName = storeName;
this._dbp = new Promise((resolve, reject) => {
const openreq = indexedDB.open(dbName, 1);
openreq.onerror = () => reject(openreq.error);
openreq.onsuccess = () => resolve(openreq.result);
// First time setup: create an empty object store
openreq.onupgradeneeded = () => {
openreq.result.createObjectStore(storeName);
};
});
}
_withIDBStore(type, callback) {
return this._dbp.then(db => new Promise((resolve, reject) => {
const transaction = db.transaction(this.storeName, type);
transaction.oncomplete = () => resolve();
transaction.onabort = transaction.onerror = () => reject(transaction.error);
callback(transaction.objectStore(this.storeName));
}));
}
}
let store;
function getDefaultStore() {
if (!store)
store = new Store();
return store;
}
function get(key, store = getDefaultStore()) {
let req;
return store._withIDBStore('readonly', store => {
req = store.get(key);
}).then(() => req.result);
}
function set(key, value, store = getDefaultStore()) {
return store._withIDBStore('readwrite', store => {
store.put(value, key);
});
}
function del(key, store = getDefaultStore()) {
return store._withIDBStore('readwrite', store => {
store.delete(key);
});
}
function clear(store = getDefaultStore()) {
return store._withIDBStore('readwrite', store => {
store.clear();
});
}
function keys(store = getDefaultStore()) {
const keys = [];
return store._withIDBStore('readonly', store => {
// This would be store.getAllKeys(), but it isn't supported by Edge or Safari.
// And openKeyCursor isn't supported by Safari.
(store.openKeyCursor || store.openCursor).call(store).onsuccess = function () {
if (!this.result)
return;
keys.push(this.result.key);
this.result.continue();
};
}).then(() => keys);
}
exports.Store = Store;
exports.get = get;
exports.set = set;
exports.del = del;
exports.clear = clear;
exports.keys = keys;
return exports;
}({}));
/*
* Returns a function which can be used as a TiddlyWiki saver.
* The saver will write the given text to the given fileHandle
*/
function createTwCustomSaver(fileHandle) {
return function (text, method, callback) {
fileHandle.createWritable()
.then(writable => {
writable.write(text);
return writable;
}).then(writable => {
writable.close();
callback(null);
}).catch(error => {
callback(error);
});
return true;
}
}
/* This saver is used when a local file is opened from disk */
function setTwCustomSaver(fileHandle) {
// Tiddlywiki Version 5.1.23 introduced the "custom saver" which will call
// a window.$tw.customSaver.save function from its current frame
// or parent frame.
window.$tw = { customSaver: { save: createTwCustomSaver(fileHandle) } };
}
/*
* This "SaveAs" saver is used when new wiki is loaded from url.
* The user is not prompted for a file to save to until the first save
*/
function setTwCustomSaveAsSaver() {
//设置默认保存文件类型为HTML文件
const opts = {
types: [{
description: 'HTML file',
accept: { 'text/html': ['.html'] },
}]
}
let writeTw;
let save = function (text, method, callback) {
if (writeTw) {
writeTw(text, method, callback);
} else {
// writeTw function is empty, so prompt the user for file handle
// and create the writeTw function
window.showSaveFilePicker(opts)
.then(fileHandle => {
writeTw = createTwCustomSaver(fileHandle);
writeTw(text, method, callback);
twFileManager.addRecent(fileHandle);
});
}
return true;
}
window.$tw = { customSaver: { save: save } };
}
const twFileManager = {
openFile: async function (fileHandle) {
if (fileHandle) {
// fileHandle may have come from indexDB in which case permission must be re-queried
const options = { mode: 'read' };
if ((await fileHandle.queryPermission(options)) !== 'granted') {
await fileHandle.requestPermission(options);
}
} else {
// No fileHandle given. Prompt user to choose one from disk
[fileHandle] = await window.showOpenFilePicker();
}
const file = await fileHandle.getFile();
const contents = await file.text();
setTwCustomSaver(fileHandle);
return { fileHandle, contents };
},
openFromUrl: async function (url) {
/*不同网站支持的访问策略不一样:vercel.app可以没有"access-control-allow-origin: *"
netlify.app一定要设定这个属性,不然不让访问。*/
const contents = await fetch(url).then(res => res.text());
setTwCustomSaveAsSaver();
return { contents };
},
/* This code modified from https://github.com/GoogleChromeLabs/text-editor/blob/main/src/inline-scripts/menu-recent.js */
/* as retrieved on 2022/03/20 */
/*
* File handles can be serialized, but only to IndexDB. Localstorage is not supported.
*/
addRecent: async function (fileHandle) {
let recentFiles = (await idbKeyval.get('recentFiles')) || [];
// If isSameEntry isn't available, we can't store the file handle
if (!fileHandle.isSameEntry) {
console.warn('不能保存最近的数据。');
return recentFiles;
}
// Loop through the list of recent files and make sure the file we're
// adding isn't already there. This is gross.
const inList = await Promise.all(recentFiles.map((f) => {
return fileHandle.isSameEntry(f);
}));
if (inList.some((val) => val)) {
return recentFiles;
}
// Add the new file handle to the top of the list, and remove any old ones.
recentFiles.unshift(fileHandle);
if (recentFiles.length > 5) {
recentFiles.pop();
}
// Save the list of recent files.
idbKeyval.set('recentFiles', recentFiles);
return recentFiles;
},
getRecent: async function () {
return (await idbKeyval.get('recentFiles')) || [];
},
clearRecent: async function () {
await idbKeyval.del('recentFiles');
}
}
// Allow indexdb to be disabled
if (window.location.hash.search("norecent") >= 0) {
const noop = async () => { return [] };
twFileManager.addRecent = noop;
twFileManager.getRecent = noop;
}
// Prevent errors if the browser doesn't support file system api
if (!window.showOpenFilePicker) {
twFileManager.openFile = async () => {
window.alert("此浏览器不支持打开文件");
return {}
}
}
if (!window.showSaveFilePicker) {
setTwCustomSaveAsSaver = () => { }
}
function replacePageContents(contents) {
if (contents) {
document.open();
document.write(contents);
document.close();
}
}
window.openFile = async function (fileHandle) {
const file = await twFileManager.openFile(fileHandle);
replacePageContents(file.contents);
if (file.fileHandle) {
twFileManager.addRecent(file.fileHandle);
}
return file;
}
window.openFromUrl = async function (url) {
const file = await twFileManager.openFromUrl(url);
replacePageContents(file.contents);
return file;
}
function displayBrowserSupportMessage() {
const elem = document.getElementById("support-message");
if (elem) {
elem.innerHTML = window.showSaveFilePicker ?
"<b>好消息!你的浏览器支持它。</b>" :
"<b>抱歉!您的浏览器不支持它。</b>"
}
}
function clearRecent() {
twFileManager.clearRecent().then(() => {
const elem = document.getElementById("recent-files");
if (elem) {
elem.innerText = "";
}
});
}
function displayRecentFiles() {
const elem = document.getElementById("recent-files");
if (elem) {
twFileManager.getRecent().
then(recentFiles => {
if (recentFiles && recentFiles.length > 0) {
const list = document.createElement('ul');
for (const recent of recentFiles) {
const li = document.createElement('li'),
button = Object.assign(document.createElement('button'), {
type: 'button',
onclick: openFile.bind(null, recent),
innerText: recent.name
});
li.appendChild(button);
list.appendChild(li);
}
const clearButton = Object.assign(document.createElement('button'), {
type: 'button',
onclick: clearRecent,
innerText: '清除最近的文件列表'
});
elem.innerText = '从最近使用过的文件开始:';
elem.appendChild(list);
elem.appendChild(clearButton);
}
})
}
}
// Miao新建的元素自适应窗口高度
function Dimensions() //函数:获取尺寸
{
var winHeight;
var height;
//获取窗口高度
if (window.innerHeight)
height = window.innerHeight;
else if ((document.body) && (document.body.clientHeight))
height = document.body.clientHeight;
winHeight = height - 16 + 'px';
document.getElementById("aside-000").style.height = winHeight;
}
window.onload = () => {
//打开页面先进行函数执行
displayBrowserSupportMessage();
displayRecentFiles();
Dimensions();
window.onresize = function () {
window.location.reload();
Dimensions();//窗口改变执行函数
}
}
</script>
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./offline-service-worker.js')
.then(function(registration) {
console.log('Service Worker registered with scope:', registration.scope);
})
.catch(function(error) {
console.error('Service Worker registration failed:', error);
});
}
</script>
</body>
</html>