活力宝 发表于 2025-3-8 13:44:41

/**
* @description 自动发现分类
* @author @kuusei
* @version 1.0.1
* @changelog 1.0.1 修复了无法翻页的问题
*/

@js:

const res = java.connect(`${baseUrl}/sort/`);
var regex = /<li ?[^>]*><a ?[^>]* ?href="([^"]*\/sort\/\d+_[\d\w\.]+\/?)">([^<]+)<\/a>(<(span|i)>共有? ?(\d+) ?本<\/(span|i)>)?<\/li>/g;
const html = res.body();

const categories = [{
title: "分类",
style: {
    "layout_flexBasisPercent": 1,
    "layout_flexGrow": 1
}
}];

let match;
while ((match = regex.exec(html)) != null) {
categories.push({
    url: match.replace("_1", "_{{page}}"),
    title: match,
    count: parseInt(match, 10),
    style: {
      "layout_flexBasisPercent": 0.25,
      "layout_flexGrow": 1
    }
});
}

JSON.stringify(categories);国内有的人可能没办法直接打开github,给它贴在这里.著作权归原作者:kuusei 所有.
页: 3 4 5 6 7 8 9 10 11 12 [13]
查看完整版本: 自动发现生成