✨ 初始提交:月读第三方书源插件集合

每个书源一个独立插件目录,含微信读书公众号订阅、书架导入等完整功能。

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
GarfieldandCopilot committed 2026-11-16 12:08:03 +08:00
commit ed44254f1c
54 files changed
+15615

No files matched your search

@@ -0,0 +1,36 @@
<!DOCTYPE html>
<!-- 微信书架分批导入页(features/wechat_import 经 web.routes 开放;逻辑在 /wechat_import.js,接口 /api/wechat_import/*) -->
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<title>微信书架导入 - 远程管理</title>
<link rel="icon" href="/favicon.ico?v=2" sizes="16x16 32x32 48x48">
<meta name="theme-color" content="#263a52">
<link rel="stylesheet" href="/style.css">
<script>try{var t=localStorage.getItem('moon-theme');if(t==='light'||t==='dark')document.documentElement.setAttribute('data-theme',t);var l=localStorage.getItem('moon-lang');if(l&&!/^zh_CN/.test(l))document.documentElement.classList.add('i18n-wait')}catch(e){}</script>
</head>
<body>
<header class="appbar"><div class="appbar-inner">
<a class="appbar-brand" href="/"><img src="/logo.jpg" alt="" width="28" height="28"><span>月读远程管理</span></a>
<nav class="appbar-nav" aria-label="页面导航">
<a href="/"><span>首页</span></a><a href="/file.html"><span>文件</span></a><a href="/input.html"><span>输入</span></a><a href="/clipboard.html"><span>剪贴板</span></a><a href="/settings.html"><span>配置</span></a><a href="/update.html"><span>更新</span></a>
</nav>
<button type="button" id="theme-toggle" class="icon-btn" aria-label="切换主题" title="主题:跟随系统"><svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor" aria-hidden="true"><path d="M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zm0 18V4a8 8 0 0 1 0 16z"/></svg></button>
</div></header>
<main class="page single-page">
<section class="panel">
<div class="panel-head"><h1>微信书架分批导入</h1></div>
<p id="info" class="state" role="status" aria-live="polite"></p>
<p>
<button type="button" id="start" class="btn" disabled>开始导入</button>
<button type="button" id="discard" class="btn" disabled>丢弃数据</button>
</p>
<div class="pg-track" role="progressbar" aria-label="导入进度"><div id="bar" class="pg-fill"></div></div>
<pre id="log"></pre>
</section>
</main>
<script src="/js.js"></script>
<script src="/wechat_import.js"></script>
</body>
</html>
@@ -0,0 +1,154 @@
/* 微信书架分批导入:下载设备落盘的 /shelf/sync 原文 → 浏览器解码 → 切批回传 → 收尾对账。接口 /api/wechat_import/*。 */
(function () {
var BATCH = 50;
var MAX_BYTES = 512 * 1024;
var API = '/api/wechat_import/';
var LISTS = ['books', 'recentBooks', 'finishReadBooks'];
var busy = false;
function post(action, body) {
return jfetch(API + action, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body || {}),
});
}
function bookId(row) {
var b = row.book || row.bookInfo || row;
var id = b.bookId || b.id || b.book_id;
return id == null ? null : String(id);
}
function progress(ratio) {
el('bar').style.width = Math.round(Math.min(1, Math.max(0, ratio)) * 100) + '%';
}
var pinger = null;
/* 导入期间定时请求设备,让它别自动休眠(休眠会停掉远程管理)。 */
function setBusy(on) {
busy = on;
clearInterval(pinger);
pinger = on ? setInterval(function () { jfetch(API + 'status', { cache: 'no-store' }).catch(function () {}); }, 15000) : null;
el('start').disabled = on;
el('discard').disabled = on;
}
/* 流式读:按已收字节更新进度(总量取设备落盘大小),读完再解码。 */
function download(total) {
return fetch(API + 'file', { cache: 'no-store' }).then(function (r) {
if (r.status === 401) return pair().then(function () { return fetch(API + 'file', { cache: 'no-store' }); });
return r;
}).then(function (r) {
if (!r.ok) throw new Error('HTTP ' + r.status);
var reader = r.body.getReader();
var chunks = [], got = 0;
function pump() {
return reader.read().then(function (res) {
if (res.done) return new Blob(chunks).text();
chunks.push(res.value);
got += res.value.length;
setState(el('info'), t('正在下载 %1 / %2 KB', Math.ceil(got / 1024), Math.ceil(total / 1024)));
progress(got / total);
return pump();
});
}
return pump();
}).then(function (text) {
setState(el('info'), t('正在解析…'));
return JSON.parse(text);
});
}
function refresh() {
return jfetch(API + 'status', { cache: 'no-store' }).then(function (s) {
var has = !!s.size;
setState(el('info'), has ? t('待导入书架数据 %1 KB', Math.ceil(s.size / 1024))
: t('设备上没有待导入的书架数据。请先在设备上对微信读书执行一次全量同步(强制刷新书架)。'));
el('start').disabled = !has;
el('discard').disabled = !has;
});
}
/* 一批:只带这批书相关的进度与分组,保证请求体远小于设备的 1MB 上限。 */
function slice(wire, list, rows) {
var ids = {};
rows.forEach(function (row) { var id = bookId(row); if (id) ids[id] = true; });
var batch = { bookProgress: (wire.bookProgress || []).filter(function (p) { return ids[String(p.bookId)]; }) };
batch[list] = rows;
batch.archive = (wire.archive || []).map(function (a) {
return { archiveId: a.archiveId, name: a.name, bookIds: (a.bookIds || []).filter(function (id) { return ids[String(id)]; }) };
}).filter(function (a) { return a.bookIds.length; });
return batch;
}
/* 请求体超过设备上限会被直接断连(浏览器只看到 Failed to fetch),超了就对半切。 */
function fit(wire, list, rows, out) {
var batch = slice(wire, list, rows);
if (rows.length > 1 && JSON.stringify(batch).length > MAX_BYTES) {
var half = rows.length >> 1;
fit(wire, list, rows.slice(0, half), out);
fit(wire, list, rows.slice(half), out);
} else {
out.push(batch);
}
}
function batches(wire) {
var out = [];
LISTS.forEach(function (list) {
var rows = wire[list] || [];
for (var i = 0; i < rows.length; i += BATCH) fit(wire, list, rows.slice(i, i + BATCH), out);
});
for (var j = 0; j < (wire.albums || []).length; j += BATCH) {
out.push({ albums: wire.albums.slice(j, j + BATCH) });
}
return out;
}
function run() {
setBusy(true);
el('log').textContent = '';
say('正在下载…');
progress(0);
var ids = [];
var stage = '下载';
jfetch(API + 'status', { cache: 'no-store' }).then(function (s) {
return download(s.size);
}).then(function (wire) {
var list = batches(wire);
var chain = Promise.resolve();
list.forEach(function (batch, i) {
chain = chain.then(function () {
stage = t('第 %1 / %2 批上传', i + 1, list.length);
return post('batch', batch).then(function (res) {
ids = ids.concat(res.ids);
el('info').textContent = t('正在导入 %1 / %2', i + 1, list.length);
progress((i + 1) / list.length);
});
});
});
return chain.then(function () { stage = '收尾'; return post('commit', { ids: ids, synckey: wire.synckey }); });
}).then(function (res) {
var msg = t('导入完成:%1 本,下架 %2 本', ids.length, res.hidden);
say(msg);
setState(el('info'), msg, 'ok');
setBusy(false);
el('start').disabled = true;
el('discard').disabled = true;
}).catch(function (e) {
var msg = t('导入失败:%1', t(stage) + ' - ' + (e && e.message || e));
say(msg);
setState(el('info'), msg, 'err');
setBusy(false);
});
}
el('start').onclick = run;
el('discard').onclick = function () {
if (busy) return;
post('discard').then(function () { say('已丢弃'); return refresh(); });
};
refresh();
})();