Skip to content

章节名格式开放API

📚 关于

提供了一系列JavaScript API函数。 这些函数可以在脚本中调用,用于新建章节、分卷是自动填充名字的场景。

API参考

章节信息

getChapterIndex()

获取当前要新建章节的索引位置。

javascript
getChapterIndex()
javascript
const currentIndex = getChapterIndex();
console.log(`当前章节索引: ${currentIndex}`);

// 计算章节号(从1开始)
const chapterNumber = currentIndex + 1;
console.log(`正在阅读第 ${chapterNumber} 章`);

返回值

  • Number - 当前要新建章节的索引值(从0开始)

getLastChapterName()

获取最后一个章节的名称。

javascript
getLastChapterName()
javascript
const lastChapter = getLastChapterName();
if (lastChapter) {
    console.log(`最后章节: ${lastChapter}`);
} else {
    console.log('没有找到章节');
}

返回值

  • String | null - 最后一个章节的名称,如果没有章节则返回null

书籍信息

getBookName()

获取当前书籍的名称。

javascript
getBookName()
javascript
const bookName = getBookName();
console.log(`书籍名: ${bookName}`);

返回值

  • String - 书籍名称

分卷信息

getCurrentGroupName()

获取当前分卷的名称。

javascript
getCurrentGroupName()
javascript
const groupName = getCurrentGroupName();
if (groupName) {
    console.log(`当前分卷: ${groupName}`);
} else {
    console.log('当前没有分卷');
}

返回值

  • String | null - 当前分卷的名称,如果没有分卷则返回null

getCurrentGroupIndex()

获取当前分卷的索引位置。

javascript
getCurrentGroupIndex()
javascript
const groupIndex = getCurrentGroupIndex();
console.log(`当前分卷索引: ${groupIndex}`);

// 显示组进度
const groupName = getCurrentGroupName();
console.log(`${groupName} (第${groupIndex + 1}卷)`);

返回值

  • Number - 当前分卷的索引值(从0开始)

⚠️注意

getCurrentGroupName()返回的是当前所在分卷的索引,从0开始,如果当前用于新建分卷,分卷序号可能应该+2。

章节列表

getCurrentGroupChapterNameList()

获取当前分卷中所有章节的名称列表。

javascript
getCurrentGroupChapterNameList()
javascript
const chapterNames = getCurrentGroupChapterNameList();
console.log('当前分卷的章节列表:');
chapterNames.forEach((name, index) => {
    console.log(`${index + 1}. ${name}`);
});

// 生成章节导航
function createGroupNavigation() {
    const chapters = getCurrentGroupChapterNameList();
    return chapters.map((name, index) => 
        `<li><a href="#chapter-${index}">${name}</a></li>`
    ).join('');
}

返回值

  • Array<String> - 包含当前分卷中所有章节名称的数组,如果没有分卷则返回空数组

getCurrentNameList()

获取名称列表:

  • 如果当前是要新建分卷,这里则是已有的分卷名列表;
  • 如果当前是要新建章节,则则是当前要新建分卷下已存在的章节名列表。
javascript
getCurrentNameList()
javascript
const allChapters = getCurrentNameList();
console.log(`总共有 ${allChapters.length} 个章节`);

// 创建完整的目录
allChapters.forEach((name, index) => {
    console.log(`章节 ${index + 1}: ${name}`);
});

// 搜索章节
function searchChapter(keyword) {
    const chapters = getCurrentNameList();
    return chapters.filter(name => 
        name.toLowerCase().includes(keyword.toLowerCase())
    );
}

返回值

  • Array<String> - 名称数组