本文发布于 465 天前,部分信息可能随时间变化。
1、工作流下载:【点击下载】
2、章节转换
// 数字转中文
function numberToChinese(num) {
const units = ['', '十', '百', '千', '万', '十', '百', '千', '亿'];
const chars = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
const str = String(num);
let result = '';
const len = str.length;
for (let i = 0; i < len; i++) {
const digit = parseInt(str[i]);
const unit = units[len - i - 1];
if (digit === 0) {
if (!result.endsWith('零') && i !== len - 1) {
result += '零';
}
} else {
result += chars[digit] + unit;
}
}
result = result.replace(/零+$/, '');
result = result.replace(/^一十/, '十');
return result;
}
// 过滤出 name === "进度" 的那一条
const items = $input.all(); // 取所有输入项
const progressItem = items.find(item => item.json.name === "进度");
if (!progressItem) {
return [{ json: { error: "未找到名称为 '进度' 的记录" } }];
}
const n = parseInt(progressItem.json.property_number, 10);
const chinese = numberToChinese(n);
return [
{
json: {
chapterName: `第${chinese}章`,
chapterNumber: n
}
}
];
3、章节提取
// 从前面节点获取原始文本
const rawText = $input.first().json.data;
// 章节名从前一个 Code 节点获取
// 注意:这里用 $node["章节转换"](根据你的节点名修改)
const inputValue = $node["章节转换"].json.chapterName.trim();
// 匹配章节标题的正则
const chapterRegex = /^第[零一二三四五六七八九十百千万0-9]+章[::].*$/gm;
// 找出所有章节标题及其位置
let chapters = [];
let match;
while ((match = chapterRegex.exec(rawText)) !== null) {
chapters.push({
index: match.index,
chapterName: match[0].trim()
});
}
chapters.push({ index: rawText.length }); // 结尾哨兵
let result = [];
// 单章提取(不再支持区间,按自动生成的章节名)
let idx = chapters.findIndex(c => c.chapterName && c.chapterName.startsWith(inputValue));
if (idx === -1) idx = chapters.findIndex(c => c.chapterName && c.chapterName.includes(inputValue));
if (idx === -1) {
throw new Error(
'找不到指定章节,请检查输入!\n'
+ '输入章节:' + inputValue + '\n'
+ '实际可选章节:\n' + chapters.map(c => c.chapterName).filter(Boolean).join('\n')
);
}
const content = rawText.substring(
chapters[idx].index + chapters[idx].chapterName.length,
chapters[idx + 1].index
).trim();
result.push({
json: {
chapter: chapters[idx].chapterName,
content: content
}
});
return result;
4、小说内容提取
const rawText = $input.first().json.data;
return [{ json: { shortText: rawText.slice(0, 1000) } }];










