本人写书源时偶尔会用到的一些代码
木木 (1) 03/12 00:27 浏览:4998
编辑删除
## 目录重新排序
~~~
.book_list a
result.sort((a, b) => {
  const hrefA = String(a).match(/href="([^"]+)"/)[1];
  const hrefB = String(b).match(/href="([^"]+)"/)[1];
  return hrefA.localeCompare(hrefB);;
});
result;
~~~
## 搜索前清空Cookies
~~~
{{cookie.removeCookie(source.getKey())}}
/search/,{
"method":"post",
"body":"searchkey={{key}}"
}
~~~
## 根据地址书籍ID拼接出目录地址
~~~
@js:
result = "/book/chapterlist?bookid=" + baseUrl.match(/book\/(\d+)/)[1]+"&pi=1";
~~~
## 根据目录地址规则拼接生成下一页规则
~~~
@js:
var page = baseUrl.match(/bookid=(\d+)&pi=(\d)/);
result = "/book/chapterlist?bookid=" + page[1]+"&pi="+(parseInt(page[2])+1);
~~~
## 基础书源(我一般以这个模板作为基础开始写)
~~~
{
    "bookSourceName": "基础书源",
    "bookSourceType": 0,
    "bookSourceUrl": "https://基础",
    "customOrder": 14,
    "enabled": true,
    "enabledCookieJar": true,
    "enabledExplore": false,
    "exploreUrl": "",
    "header": "{\n\"User-Agent\":\"Mozilla/5.0 (Linux; Android 9) Mobile Safari/537.36\",\"referer\":\"{{baseUrl}}\",\n}",
    "lastUpdateTime": 1735359964557,
    "respondTime": 180000,
    "ruleBookInfo": {
        "author": ".shortinfo@a@text",
        "intro": ".desc@text",
        "kind": ".title .c1 a@text",
        "lastChapter": ".newestChapter@a@text",
        "name": ".title .name@text",
        "tocUrl": "@js:\nresult = \"/book/chapterlist?bookid=\" + baseUrl.match(/book\\/(\\d+)/)[1]+\"&pi=1\";",
        "wordCount": ""
    },
    "ruleContent": {
        "content": ".novelcontent@html",
        "nextContentUrl": ""
    },
    "ruleExplore": {
        "author": "",
        "bookList": "",
        "bookUrl": "",
        "intro": "",
        "name": "",
        "wordCount": ""
    },
    "ruleSearch": {
        "author": ".author@text",
        "bookList": "li",
        "bookUrl": "a@href",
        "coverUrl": ".imgbox@img.0@src",
        "intro": ".desc@text",
        "kind": "",
        "name": "h2@text",
        "wordCount": ""
    },
    "ruleToc": {
        "chapterList": "li a",
        "chapterName": "em@text",
        "chapterUrl": "href",
        "isPay": "",
        "nextTocUrl": "@js:\nvar page = baseUrl.match(/bookid=(\\d+)&pi=(\\d)/);\nresult = \"/book/chapterlist?bookid=\" + page[1]+\"&pi=\"+(parseInt(page[2])+1);"
    },
    "searchUrl": "/api/query,{\n  \"body\": \"q={{key}}\",\n  \"charset\": \"UTF-8\",\n  \"method\": \"POST\"\n}",
    "weight": 0
}
~~~