@acanthis-dec/linovelib 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +45 -2
- package/dist/index.mjs +1456 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -487,6 +487,1350 @@ async function getVolumeCoverUrl(id, novelId, fetchClient) {
|
|
|
487
487
|
if (!volume) throw new Error(`Volume not found for ID: ${id}`);
|
|
488
488
|
return $(volume).find("a.volume-cover img").attr("data-original") || "";
|
|
489
489
|
}
|
|
490
|
+
// src/explore/common.ts
|
|
491
|
+
const LINOVELIB_DESKTOP_BASE = "https://www.linovelib.com";
|
|
492
|
+
function cleanInlineText(raw) {
|
|
493
|
+
return (raw ?? "").replace(/\s+/g, " ").trim();
|
|
494
|
+
}
|
|
495
|
+
function cleanBlockText(raw) {
|
|
496
|
+
return (raw ?? "").replace(/\r\n?/g, "\n").split("\n").map((line) => line.replace(/[ \t]+/g, " ").trim()).filter((line) => line.length > 0).join("\n").trim();
|
|
497
|
+
}
|
|
498
|
+
function extractNovelIdFromHref(href) {
|
|
499
|
+
if (!href) return null;
|
|
500
|
+
return href.trim().match(/(?:^|\/)novel\/(\d+)\.html(?:[?#]|$)/)?.[1] ?? null;
|
|
501
|
+
}
|
|
502
|
+
function extractChapterIdFromHref(href, novelId) {
|
|
503
|
+
if (!href) return null;
|
|
504
|
+
const match = href.trim().match(/(?:^|\/)novel\/(\d+)\/(\d+)(?:_\d+)?\.html(?:[?#]|$)/);
|
|
505
|
+
if (!match) return null;
|
|
506
|
+
if (novelId && match[1] !== novelId) return null;
|
|
507
|
+
return match[2] ?? null;
|
|
508
|
+
}
|
|
509
|
+
function isPlaceholderCoverUrl(rawSrc) {
|
|
510
|
+
if (!rawSrc) return true;
|
|
511
|
+
const lower = rawSrc.trim().toLowerCase();
|
|
512
|
+
return lower.length === 0 || lower.includes("book-cover-no.svg") || lower.startsWith("data:");
|
|
513
|
+
}
|
|
514
|
+
function resolveDesktopCoverUrl(novelId, rawSrc) {
|
|
515
|
+
if (!rawSrc || isPlaceholderCoverUrl(rawSrc)) return novelIdToCoverUrl(novelId);
|
|
516
|
+
const trimmed = rawSrc.trim();
|
|
517
|
+
if (trimmed.startsWith("//")) return `https:${trimmed}`;
|
|
518
|
+
if (trimmed.startsWith("https://") || trimmed.startsWith("http://")) return trimmed;
|
|
519
|
+
if (trimmed.startsWith("/")) return `${LINOVELIB_DESKTOP_BASE}${trimmed}`;
|
|
520
|
+
return novelIdToCoverUrl(novelId);
|
|
521
|
+
}
|
|
522
|
+
function extractImgCoverUrl(novelId, $img) {
|
|
523
|
+
const dataOriginal = $img.attr("data-original");
|
|
524
|
+
if (!isPlaceholderCoverUrl(dataOriginal)) return resolveDesktopCoverUrl(novelId, dataOriginal);
|
|
525
|
+
return resolveDesktopCoverUrl(novelId, $img.attr("src"));
|
|
526
|
+
}
|
|
527
|
+
function parseNovelStatusText(raw) {
|
|
528
|
+
const text = cleanInlineText(raw);
|
|
529
|
+
if (text.includes("完结") || text.includes("完本")) return "completed";
|
|
530
|
+
if (text.includes("连载")) return "ongoing";
|
|
531
|
+
return "unknown";
|
|
532
|
+
}
|
|
533
|
+
function buildExploreNovelItem(input) {
|
|
534
|
+
const item = {
|
|
535
|
+
id: input.id,
|
|
536
|
+
platform: "linovelib",
|
|
537
|
+
title: input.title,
|
|
538
|
+
coverUrl: input.coverUrl ?? novelIdToCoverUrl(input.id)
|
|
539
|
+
};
|
|
540
|
+
if (input.author) item.author = input.author;
|
|
541
|
+
if (input.summary) item.summary = input.summary;
|
|
542
|
+
if (input.status !== void 0) item.status = input.status;
|
|
543
|
+
if (input.category) item.category = input.category;
|
|
544
|
+
if (input.genres && input.genres.length > 0) item.genres = input.genres;
|
|
545
|
+
if (input.latestChapter) item.latestChapter = input.latestChapter;
|
|
546
|
+
if (input.latestChapterId) item.latestChapterId = input.latestChapterId;
|
|
547
|
+
if (input.wordCount) item.wordCount = input.wordCount;
|
|
548
|
+
if (input.updatedAt) item.updatedAt = input.updatedAt;
|
|
549
|
+
if (input.rank !== void 0) item.rank = input.rank;
|
|
550
|
+
return item;
|
|
551
|
+
}
|
|
552
|
+
// src/explore/schema.ts
|
|
553
|
+
const CHANNELS = [
|
|
554
|
+
{
|
|
555
|
+
id: "home",
|
|
556
|
+
label: "全站首页",
|
|
557
|
+
requiresChallenge: false
|
|
558
|
+
},
|
|
559
|
+
{
|
|
560
|
+
id: "dengekibunko",
|
|
561
|
+
label: "电击文库",
|
|
562
|
+
requiresChallenge: true
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
id: "fujimibunko",
|
|
566
|
+
label: "富士见文库",
|
|
567
|
+
requiresChallenge: true
|
|
568
|
+
},
|
|
569
|
+
{
|
|
570
|
+
id: "kadokawabunko",
|
|
571
|
+
label: "角川文库",
|
|
572
|
+
requiresChallenge: true
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
id: "emuefubunkojei",
|
|
576
|
+
label: "MF文库J",
|
|
577
|
+
requiresChallenge: true
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
id: "famitsubunko",
|
|
581
|
+
label: "Fami通文库",
|
|
582
|
+
requiresChallenge: true
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
id: "gagraphicbunko",
|
|
586
|
+
label: "GA文库",
|
|
587
|
+
requiresChallenge: true
|
|
588
|
+
},
|
|
589
|
+
{
|
|
590
|
+
id: "hobbyjapanbunko",
|
|
591
|
+
label: "HJ文库",
|
|
592
|
+
requiresChallenge: true
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
id: "ichijinsha",
|
|
596
|
+
label: "一迅社",
|
|
597
|
+
requiresChallenge: true
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
id: "shueisha",
|
|
601
|
+
label: "集英社",
|
|
602
|
+
requiresChallenge: true
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
id: "shogakukan",
|
|
606
|
+
label: "小学馆",
|
|
607
|
+
requiresChallenge: true
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
id: "kodansha",
|
|
611
|
+
label: "讲谈社",
|
|
612
|
+
requiresChallenge: true
|
|
613
|
+
},
|
|
614
|
+
{
|
|
615
|
+
id: "teenagebunko",
|
|
616
|
+
label: "少女文库",
|
|
617
|
+
requiresChallenge: true
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
id: "other",
|
|
621
|
+
label: "其他文库",
|
|
622
|
+
requiresChallenge: true
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
id: "chineselightnovel",
|
|
626
|
+
label: "华文轻小说",
|
|
627
|
+
requiresChallenge: true
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
id: "weblightnovel",
|
|
631
|
+
label: "Web轻小说",
|
|
632
|
+
requiresChallenge: true
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
id: "koreanlightnovel",
|
|
636
|
+
label: "韩国轻小说",
|
|
637
|
+
requiresChallenge: true
|
|
638
|
+
}
|
|
639
|
+
];
|
|
640
|
+
const RANKINGS = [
|
|
641
|
+
{
|
|
642
|
+
id: "monthvisit",
|
|
643
|
+
label: "月点击榜",
|
|
644
|
+
supportsAll: true,
|
|
645
|
+
supportsFull: true
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
id: "weekvisit",
|
|
649
|
+
label: "周点击榜",
|
|
650
|
+
supportsAll: true,
|
|
651
|
+
supportsFull: true
|
|
652
|
+
},
|
|
653
|
+
{
|
|
654
|
+
id: "monthvote",
|
|
655
|
+
label: "月推荐榜",
|
|
656
|
+
supportsAll: true,
|
|
657
|
+
supportsFull: true
|
|
658
|
+
},
|
|
659
|
+
{
|
|
660
|
+
id: "weekvote",
|
|
661
|
+
label: "周推荐榜",
|
|
662
|
+
supportsAll: true,
|
|
663
|
+
supportsFull: true
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
id: "monthflower",
|
|
667
|
+
label: "月鲜花榜",
|
|
668
|
+
supportsAll: true,
|
|
669
|
+
supportsFull: true
|
|
670
|
+
},
|
|
671
|
+
{
|
|
672
|
+
id: "weekflower",
|
|
673
|
+
label: "周鲜花榜",
|
|
674
|
+
supportsAll: true,
|
|
675
|
+
supportsFull: true
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
id: "monthegg",
|
|
679
|
+
label: "月鸡蛋榜",
|
|
680
|
+
supportsAll: true,
|
|
681
|
+
supportsFull: true
|
|
682
|
+
},
|
|
683
|
+
{
|
|
684
|
+
id: "weekegg",
|
|
685
|
+
label: "周鸡蛋榜",
|
|
686
|
+
supportsAll: true,
|
|
687
|
+
supportsFull: true
|
|
688
|
+
},
|
|
689
|
+
{
|
|
690
|
+
id: "lastupdate",
|
|
691
|
+
label: "最近更新",
|
|
692
|
+
supportsAll: true,
|
|
693
|
+
supportsFull: true
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
id: "postdate",
|
|
697
|
+
label: "最新入库",
|
|
698
|
+
supportsAll: true,
|
|
699
|
+
supportsFull: true
|
|
700
|
+
},
|
|
701
|
+
{
|
|
702
|
+
id: "goodnum",
|
|
703
|
+
label: "收藏榜",
|
|
704
|
+
supportsAll: true,
|
|
705
|
+
supportsFull: true
|
|
706
|
+
},
|
|
707
|
+
{
|
|
708
|
+
id: "newhot",
|
|
709
|
+
label: "新书榜",
|
|
710
|
+
supportsAll: true,
|
|
711
|
+
supportsFull: true
|
|
712
|
+
},
|
|
713
|
+
{
|
|
714
|
+
id: "allvisit",
|
|
715
|
+
label: "总点击榜",
|
|
716
|
+
supportsAll: false,
|
|
717
|
+
supportsFull: true
|
|
718
|
+
}
|
|
719
|
+
];
|
|
720
|
+
const SORT_OPTIONS = [
|
|
721
|
+
{
|
|
722
|
+
value: "lastupdate",
|
|
723
|
+
label: "更新时间"
|
|
724
|
+
},
|
|
725
|
+
{
|
|
726
|
+
value: "weekvisit",
|
|
727
|
+
label: "周点击"
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
value: "monthvisit",
|
|
731
|
+
label: "月点击"
|
|
732
|
+
},
|
|
733
|
+
{
|
|
734
|
+
value: "weekvote",
|
|
735
|
+
label: "周推荐"
|
|
736
|
+
},
|
|
737
|
+
{
|
|
738
|
+
value: "monthvote",
|
|
739
|
+
label: "月推荐"
|
|
740
|
+
},
|
|
741
|
+
{
|
|
742
|
+
value: "weekflower",
|
|
743
|
+
label: "周鲜花"
|
|
744
|
+
},
|
|
745
|
+
{
|
|
746
|
+
value: "monthflower",
|
|
747
|
+
label: "月鲜花"
|
|
748
|
+
},
|
|
749
|
+
{
|
|
750
|
+
value: "goodnum",
|
|
751
|
+
label: "收藏数"
|
|
752
|
+
},
|
|
753
|
+
{
|
|
754
|
+
value: "postdate",
|
|
755
|
+
label: "入库时间"
|
|
756
|
+
}
|
|
757
|
+
];
|
|
758
|
+
const REGION_OPTIONS = [
|
|
759
|
+
{
|
|
760
|
+
value: "0",
|
|
761
|
+
label: "不限"
|
|
762
|
+
},
|
|
763
|
+
{
|
|
764
|
+
value: "1",
|
|
765
|
+
label: "日本轻小说"
|
|
766
|
+
},
|
|
767
|
+
{
|
|
768
|
+
value: "2",
|
|
769
|
+
label: "华文轻小说"
|
|
770
|
+
},
|
|
771
|
+
{
|
|
772
|
+
value: "3",
|
|
773
|
+
label: "Web轻小说"
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
value: "4",
|
|
777
|
+
label: "轻改漫画"
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
value: "5",
|
|
781
|
+
label: "韩国轻小说"
|
|
782
|
+
}
|
|
783
|
+
];
|
|
784
|
+
const TAG_OPTIONS = [
|
|
785
|
+
{
|
|
786
|
+
value: "0",
|
|
787
|
+
label: "不限"
|
|
788
|
+
},
|
|
789
|
+
{
|
|
790
|
+
value: "64",
|
|
791
|
+
label: "恋爱"
|
|
792
|
+
},
|
|
793
|
+
{
|
|
794
|
+
value: "48",
|
|
795
|
+
label: "后宫"
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
value: "63",
|
|
799
|
+
label: "校园"
|
|
800
|
+
},
|
|
801
|
+
{
|
|
802
|
+
value: "27",
|
|
803
|
+
label: "百合"
|
|
804
|
+
},
|
|
805
|
+
{
|
|
806
|
+
value: "26",
|
|
807
|
+
label: "转生"
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
value: "47",
|
|
811
|
+
label: "异世界"
|
|
812
|
+
},
|
|
813
|
+
{
|
|
814
|
+
value: "15",
|
|
815
|
+
label: "奇幻"
|
|
816
|
+
},
|
|
817
|
+
{
|
|
818
|
+
value: "61",
|
|
819
|
+
label: "冒险"
|
|
820
|
+
},
|
|
821
|
+
{
|
|
822
|
+
value: "222",
|
|
823
|
+
label: "欢乐向"
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
value: "231",
|
|
827
|
+
label: "女性视角"
|
|
828
|
+
},
|
|
829
|
+
{
|
|
830
|
+
value: "219",
|
|
831
|
+
label: "龙傲天"
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
value: "96",
|
|
835
|
+
label: "魔法"
|
|
836
|
+
},
|
|
837
|
+
{
|
|
838
|
+
value: "67",
|
|
839
|
+
label: "青春"
|
|
840
|
+
},
|
|
841
|
+
{
|
|
842
|
+
value: "31",
|
|
843
|
+
label: "性转"
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
value: "198",
|
|
847
|
+
label: "病娇"
|
|
848
|
+
},
|
|
849
|
+
{
|
|
850
|
+
value: "217",
|
|
851
|
+
label: "妹妹"
|
|
852
|
+
},
|
|
853
|
+
{
|
|
854
|
+
value: "225",
|
|
855
|
+
label: "青梅竹马"
|
|
856
|
+
},
|
|
857
|
+
{
|
|
858
|
+
value: "18",
|
|
859
|
+
label: "战斗"
|
|
860
|
+
},
|
|
861
|
+
{
|
|
862
|
+
value: "256",
|
|
863
|
+
label: "NTR"
|
|
864
|
+
},
|
|
865
|
+
{
|
|
866
|
+
value: "223",
|
|
867
|
+
label: "人外"
|
|
868
|
+
},
|
|
869
|
+
{
|
|
870
|
+
value: "227",
|
|
871
|
+
label: "大小姐"
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
value: "189",
|
|
875
|
+
label: "黑暗"
|
|
876
|
+
},
|
|
877
|
+
{
|
|
878
|
+
value: "68",
|
|
879
|
+
label: "悬疑"
|
|
880
|
+
},
|
|
881
|
+
{
|
|
882
|
+
value: "56",
|
|
883
|
+
label: "科幻"
|
|
884
|
+
},
|
|
885
|
+
{
|
|
886
|
+
value: "201",
|
|
887
|
+
label: "伪娘"
|
|
888
|
+
},
|
|
889
|
+
{
|
|
890
|
+
value: "55",
|
|
891
|
+
label: "战争"
|
|
892
|
+
},
|
|
893
|
+
{
|
|
894
|
+
value: "185",
|
|
895
|
+
label: "萝莉"
|
|
896
|
+
},
|
|
897
|
+
{
|
|
898
|
+
value: "229",
|
|
899
|
+
label: "复仇"
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
value: "199",
|
|
903
|
+
label: "斗智"
|
|
904
|
+
},
|
|
905
|
+
{
|
|
906
|
+
value: "131",
|
|
907
|
+
label: "异能"
|
|
908
|
+
},
|
|
909
|
+
{
|
|
910
|
+
value: "241",
|
|
911
|
+
label: "猎奇"
|
|
912
|
+
},
|
|
913
|
+
{
|
|
914
|
+
value: "191",
|
|
915
|
+
label: "轻文学"
|
|
916
|
+
},
|
|
917
|
+
{
|
|
918
|
+
value: "60",
|
|
919
|
+
label: "职场"
|
|
920
|
+
},
|
|
921
|
+
{
|
|
922
|
+
value: "226",
|
|
923
|
+
label: "经营"
|
|
924
|
+
},
|
|
925
|
+
{
|
|
926
|
+
value: "246",
|
|
927
|
+
label: "JK"
|
|
928
|
+
},
|
|
929
|
+
{
|
|
930
|
+
value: "135",
|
|
931
|
+
label: "机战"
|
|
932
|
+
},
|
|
933
|
+
{
|
|
934
|
+
value: "261",
|
|
935
|
+
label: "女儿"
|
|
936
|
+
},
|
|
937
|
+
{
|
|
938
|
+
value: "221",
|
|
939
|
+
label: "末日"
|
|
940
|
+
},
|
|
941
|
+
{
|
|
942
|
+
value: "220",
|
|
943
|
+
label: "犯罪"
|
|
944
|
+
},
|
|
945
|
+
{
|
|
946
|
+
value: "239",
|
|
947
|
+
label: "旅行"
|
|
948
|
+
},
|
|
949
|
+
{
|
|
950
|
+
value: "124",
|
|
951
|
+
label: "惊悚"
|
|
952
|
+
},
|
|
953
|
+
{
|
|
954
|
+
value: "98",
|
|
955
|
+
label: "治愈"
|
|
956
|
+
},
|
|
957
|
+
{
|
|
958
|
+
value: "97",
|
|
959
|
+
label: "推理"
|
|
960
|
+
},
|
|
961
|
+
{
|
|
962
|
+
value: "205",
|
|
963
|
+
label: "日本文学"
|
|
964
|
+
},
|
|
965
|
+
{
|
|
966
|
+
value: "248",
|
|
967
|
+
label: "游戏"
|
|
968
|
+
},
|
|
969
|
+
{
|
|
970
|
+
value: "228",
|
|
971
|
+
label: "耽美"
|
|
972
|
+
},
|
|
973
|
+
{
|
|
974
|
+
value: "211",
|
|
975
|
+
label: "美食"
|
|
976
|
+
},
|
|
977
|
+
{
|
|
978
|
+
value: "245",
|
|
979
|
+
label: "群像"
|
|
980
|
+
},
|
|
981
|
+
{
|
|
982
|
+
value: "249",
|
|
983
|
+
label: "大逃杀"
|
|
984
|
+
},
|
|
985
|
+
{
|
|
986
|
+
value: "233",
|
|
987
|
+
label: "音乐"
|
|
988
|
+
},
|
|
989
|
+
{
|
|
990
|
+
value: "132",
|
|
991
|
+
label: "格斗"
|
|
992
|
+
},
|
|
993
|
+
{
|
|
994
|
+
value: "28",
|
|
995
|
+
label: "热血"
|
|
996
|
+
},
|
|
997
|
+
{
|
|
998
|
+
value: "180",
|
|
999
|
+
label: "温馨"
|
|
1000
|
+
},
|
|
1001
|
+
{
|
|
1002
|
+
value: "224",
|
|
1003
|
+
label: "脑洞"
|
|
1004
|
+
},
|
|
1005
|
+
{
|
|
1006
|
+
value: "328",
|
|
1007
|
+
label: "恶役"
|
|
1008
|
+
},
|
|
1009
|
+
{
|
|
1010
|
+
value: "304",
|
|
1011
|
+
label: "JC"
|
|
1012
|
+
},
|
|
1013
|
+
{
|
|
1014
|
+
value: "254",
|
|
1015
|
+
label: "间谍"
|
|
1016
|
+
},
|
|
1017
|
+
{
|
|
1018
|
+
value: "146",
|
|
1019
|
+
label: "竞技"
|
|
1020
|
+
},
|
|
1021
|
+
{
|
|
1022
|
+
value: "263",
|
|
1023
|
+
label: "宅文化"
|
|
1024
|
+
},
|
|
1025
|
+
{
|
|
1026
|
+
value: "333",
|
|
1027
|
+
label: "同人"
|
|
1028
|
+
}
|
|
1029
|
+
];
|
|
1030
|
+
const PROGRESS_OPTIONS = [
|
|
1031
|
+
{
|
|
1032
|
+
value: "0",
|
|
1033
|
+
label: "不限"
|
|
1034
|
+
},
|
|
1035
|
+
{
|
|
1036
|
+
value: "1",
|
|
1037
|
+
label: "新书上传"
|
|
1038
|
+
},
|
|
1039
|
+
{
|
|
1040
|
+
value: "2",
|
|
1041
|
+
label: "情节展开"
|
|
1042
|
+
},
|
|
1043
|
+
{
|
|
1044
|
+
value: "3",
|
|
1045
|
+
label: "精彩纷呈"
|
|
1046
|
+
},
|
|
1047
|
+
{
|
|
1048
|
+
value: "4",
|
|
1049
|
+
label: "接近尾声"
|
|
1050
|
+
},
|
|
1051
|
+
{
|
|
1052
|
+
value: "5",
|
|
1053
|
+
label: "已经完本"
|
|
1054
|
+
}
|
|
1055
|
+
];
|
|
1056
|
+
const ANIME_OPTIONS = [
|
|
1057
|
+
{
|
|
1058
|
+
value: "0",
|
|
1059
|
+
label: "不限"
|
|
1060
|
+
},
|
|
1061
|
+
{
|
|
1062
|
+
value: "1",
|
|
1063
|
+
label: "已动画化"
|
|
1064
|
+
},
|
|
1065
|
+
{
|
|
1066
|
+
value: "2",
|
|
1067
|
+
label: "未动画化"
|
|
1068
|
+
}
|
|
1069
|
+
];
|
|
1070
|
+
const WORDS_OPTIONS = [
|
|
1071
|
+
{
|
|
1072
|
+
value: "0",
|
|
1073
|
+
label: "不限"
|
|
1074
|
+
},
|
|
1075
|
+
{
|
|
1076
|
+
value: "1",
|
|
1077
|
+
label: "30万以下"
|
|
1078
|
+
},
|
|
1079
|
+
{
|
|
1080
|
+
value: "2",
|
|
1081
|
+
label: "30-50万"
|
|
1082
|
+
},
|
|
1083
|
+
{
|
|
1084
|
+
value: "3",
|
|
1085
|
+
label: "50-100万"
|
|
1086
|
+
},
|
|
1087
|
+
{
|
|
1088
|
+
value: "4",
|
|
1089
|
+
label: "100-200万"
|
|
1090
|
+
},
|
|
1091
|
+
{
|
|
1092
|
+
value: "5",
|
|
1093
|
+
label: "200万以上"
|
|
1094
|
+
}
|
|
1095
|
+
];
|
|
1096
|
+
const UPDATED_OPTIONS = [
|
|
1097
|
+
{
|
|
1098
|
+
value: "0",
|
|
1099
|
+
label: "不限"
|
|
1100
|
+
},
|
|
1101
|
+
{
|
|
1102
|
+
value: "1",
|
|
1103
|
+
label: "三日内"
|
|
1104
|
+
},
|
|
1105
|
+
{
|
|
1106
|
+
value: "2",
|
|
1107
|
+
label: "七日内"
|
|
1108
|
+
},
|
|
1109
|
+
{
|
|
1110
|
+
value: "3",
|
|
1111
|
+
label: "半月内"
|
|
1112
|
+
},
|
|
1113
|
+
{
|
|
1114
|
+
value: "4",
|
|
1115
|
+
label: "一月内"
|
|
1116
|
+
}
|
|
1117
|
+
];
|
|
1118
|
+
const LINOVELIB_EXPLORE_SCHEMA = {
|
|
1119
|
+
platform: "linovelib",
|
|
1120
|
+
supportsHome: true,
|
|
1121
|
+
channels: CHANNELS,
|
|
1122
|
+
rankings: RANKINGS,
|
|
1123
|
+
catalogRequiresChallenge: true,
|
|
1124
|
+
catalogFilters: [
|
|
1125
|
+
{
|
|
1126
|
+
key: "sort",
|
|
1127
|
+
label: "排序方式",
|
|
1128
|
+
defaultValue: "lastupdate",
|
|
1129
|
+
options: SORT_OPTIONS
|
|
1130
|
+
},
|
|
1131
|
+
{
|
|
1132
|
+
key: "region",
|
|
1133
|
+
label: "文库地区",
|
|
1134
|
+
defaultValue: "0",
|
|
1135
|
+
options: REGION_OPTIONS
|
|
1136
|
+
},
|
|
1137
|
+
{
|
|
1138
|
+
key: "tag",
|
|
1139
|
+
label: "作品主题",
|
|
1140
|
+
defaultValue: "0",
|
|
1141
|
+
options: TAG_OPTIONS
|
|
1142
|
+
},
|
|
1143
|
+
{
|
|
1144
|
+
key: "progress",
|
|
1145
|
+
label: "写作进度",
|
|
1146
|
+
defaultValue: "0",
|
|
1147
|
+
options: PROGRESS_OPTIONS
|
|
1148
|
+
},
|
|
1149
|
+
{
|
|
1150
|
+
key: "anime",
|
|
1151
|
+
label: "是否动画化",
|
|
1152
|
+
defaultValue: "0",
|
|
1153
|
+
options: ANIME_OPTIONS
|
|
1154
|
+
},
|
|
1155
|
+
{
|
|
1156
|
+
key: "words",
|
|
1157
|
+
label: "作品字数",
|
|
1158
|
+
defaultValue: "0",
|
|
1159
|
+
options: WORDS_OPTIONS
|
|
1160
|
+
},
|
|
1161
|
+
{
|
|
1162
|
+
key: "updated",
|
|
1163
|
+
label: "更新时间",
|
|
1164
|
+
defaultValue: "0",
|
|
1165
|
+
options: UPDATED_OPTIONS
|
|
1166
|
+
}
|
|
1167
|
+
]
|
|
1168
|
+
};
|
|
1169
|
+
const LINOVELIB_CHANNEL_IDS = new Set(CHANNELS.map((c) => c.id));
|
|
1170
|
+
const LINOVELIB_RANKING_IDS = new Set(RANKINGS.map((r) => r.id));
|
|
1171
|
+
const LINOVELIB_CATALOG_SORT_IDS = new Set(SORT_OPTIONS.map((o) => o.value));
|
|
1172
|
+
const LINOVELIB_CATALOG_REGION_IDS = new Set(REGION_OPTIONS.map((o) => o.value));
|
|
1173
|
+
const LINOVELIB_CATALOG_TAG_IDS = new Set(TAG_OPTIONS.map((o) => o.value));
|
|
1174
|
+
const LINOVELIB_CATALOG_PROGRESS_IDS = new Set(PROGRESS_OPTIONS.map((o) => o.value));
|
|
1175
|
+
const LINOVELIB_CATALOG_ANIME_IDS = new Set(ANIME_OPTIONS.map((o) => o.value));
|
|
1176
|
+
const LINOVELIB_CATALOG_WORDS_IDS = new Set(WORDS_OPTIONS.map((o) => o.value));
|
|
1177
|
+
const LINOVELIB_CATALOG_UPDATED_IDS = new Set(UPDATED_OPTIONS.map((o) => o.value));
|
|
1178
|
+
const RANKING_MAP = new Map(RANKINGS.map((r) => [r.id, r]));
|
|
1179
|
+
const CHANNEL_MAP = new Map(CHANNELS.map((c) => [c.id, c]));
|
|
1180
|
+
function getLinovelibChannelOption(channel) {
|
|
1181
|
+
return CHANNEL_MAP.get(channel);
|
|
1182
|
+
}
|
|
1183
|
+
function isValidLinovelibChannel(channel) {
|
|
1184
|
+
return LINOVELIB_CHANNEL_IDS.has(channel);
|
|
1185
|
+
}
|
|
1186
|
+
function isValidLinovelibRanking(rank, full) {
|
|
1187
|
+
const option = RANKING_MAP.get(rank);
|
|
1188
|
+
if (!option) return false;
|
|
1189
|
+
return full ? option.supportsFull : option.supportsAll;
|
|
1190
|
+
}
|
|
1191
|
+
function assertAllowedOption(key, value, allowed) {
|
|
1192
|
+
if (!allowed.has(value)) throw new Error(`Invalid linovelib catalog ${key}: ${value}`);
|
|
1193
|
+
return value;
|
|
1194
|
+
}
|
|
1195
|
+
function normalizeCatalogOptions(options) {
|
|
1196
|
+
const sort = assertAllowedOption("sort", options?.sort ?? "lastupdate", LINOVELIB_CATALOG_SORT_IDS);
|
|
1197
|
+
const region = assertAllowedOption("region", options?.region ?? "0", LINOVELIB_CATALOG_REGION_IDS);
|
|
1198
|
+
const tag = assertAllowedOption("tag", options?.tag ?? "0", LINOVELIB_CATALOG_TAG_IDS);
|
|
1199
|
+
const progress = assertAllowedOption("progress", options?.progress ?? "0", LINOVELIB_CATALOG_PROGRESS_IDS);
|
|
1200
|
+
const anime = assertAllowedOption("anime", options?.anime ?? "0", LINOVELIB_CATALOG_ANIME_IDS);
|
|
1201
|
+
const words = assertAllowedOption("words", options?.words ?? "0", LINOVELIB_CATALOG_WORDS_IDS);
|
|
1202
|
+
const updated = assertAllowedOption("updated", options?.updated ?? "0", LINOVELIB_CATALOG_UPDATED_IDS);
|
|
1203
|
+
const page = options?.page ?? 1;
|
|
1204
|
+
if (!Number.isInteger(page) || page < 1) throw new Error(`Invalid linovelib catalog page: ${page}`);
|
|
1205
|
+
return {
|
|
1206
|
+
sort,
|
|
1207
|
+
region,
|
|
1208
|
+
tag,
|
|
1209
|
+
progress,
|
|
1210
|
+
anime,
|
|
1211
|
+
words,
|
|
1212
|
+
updated,
|
|
1213
|
+
page
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
1216
|
+
// src/explore/catalog.ts
|
|
1217
|
+
function buildCatalogUrl(options) {
|
|
1218
|
+
const normalized = normalizeCatalogOptions(options);
|
|
1219
|
+
return `${LINOVELIB_DESKTOP_BASE}/wenku/${normalized.sort}_${normalized.tag}_${normalized.progress}_${normalized.anime}_${normalized.region}_0_0_${normalized.words}_${normalized.page}_${normalized.updated}.html`;
|
|
1220
|
+
}
|
|
1221
|
+
function parseBookilnkMeta(spans, fallbackText) {
|
|
1222
|
+
const parts = spans.length > 0 ? spans : fallbackText.split(/[|/]/).map((s) => cleanInlineText(s)).filter((s) => s.length > 0);
|
|
1223
|
+
if (parts.length === 0) return {};
|
|
1224
|
+
const result = {};
|
|
1225
|
+
if (parts[0]) result.author = parts[0];
|
|
1226
|
+
if (parts[1]) result.category = parts[1];
|
|
1227
|
+
if (parts.length >= 4) {
|
|
1228
|
+
if (parts[2]) result.status = parseNovelStatusText(parts[2]);
|
|
1229
|
+
if (parts[3]) result.updatedAt = parts[3];
|
|
1230
|
+
} else if (parts.length === 3 && parts[2]) {
|
|
1231
|
+
if (/^\d{2,4}[-/]\d{2}(?:[-/]\d{2})?/.test(parts[2])) result.updatedAt = parts[2];
|
|
1232
|
+
else result.status = parseNovelStatusText(parts[2]);
|
|
1233
|
+
}
|
|
1234
|
+
return result;
|
|
1235
|
+
}
|
|
1236
|
+
function parseCatalogHtml(html, page) {
|
|
1237
|
+
const $ = load(html);
|
|
1238
|
+
const items = [];
|
|
1239
|
+
$(".store_collist .bookbox").each((_, el) => {
|
|
1240
|
+
const $el = $(el);
|
|
1241
|
+
const $bookNameLink = $el.find(".bookname a").first();
|
|
1242
|
+
const $bookImgLink = $el.find(".bookimg a").first();
|
|
1243
|
+
const $fallbackLink = $el.find("a[href*='/novel/']").first();
|
|
1244
|
+
const id = extractNovelIdFromHref($bookNameLink.attr("href")) ?? extractNovelIdFromHref($bookImgLink.attr("href")) ?? extractNovelIdFromHref($fallbackLink.attr("href"));
|
|
1245
|
+
if (!id) return;
|
|
1246
|
+
const title = cleanInlineText($bookNameLink.text()) || cleanInlineText($el.find(".bookname").text()) || cleanInlineText($el.find(".bookimg img").attr("alt")) || cleanInlineText($fallbackLink.text());
|
|
1247
|
+
if (!title) return;
|
|
1248
|
+
const coverUrl = extractImgCoverUrl(id, $el.find(".bookimg img, img").first());
|
|
1249
|
+
const meta = parseBookilnkMeta($el.find(".bookilnk span").map((__, span) => cleanInlineText($(span).text())).get().filter((s) => s.length > 0), $el.find(".bookilnk").text());
|
|
1250
|
+
const summary = cleanBlockText($el.find(".bookintro").text()) || void 0;
|
|
1251
|
+
const genres = $el.find(".bookupdate b").map((__, b) => $(b).text()).get().join(" ").split(/\s+/).map((g) => g.trim()).filter((g) => g.length > 0);
|
|
1252
|
+
const $chapterLink = $el.find(".bookupdate a[href*='/novel/'], a[href*='/novel/']").filter((__, a) => extractChapterIdFromHref($(a).attr("href"), id) !== null).first();
|
|
1253
|
+
const latestChapterId = extractChapterIdFromHref($chapterLink.attr("href"), id) ?? void 0;
|
|
1254
|
+
const latestChapter = latestChapterId ? cleanInlineText($chapterLink.text()) || void 0 : void 0;
|
|
1255
|
+
const itemInput = {
|
|
1256
|
+
id,
|
|
1257
|
+
title,
|
|
1258
|
+
coverUrl
|
|
1259
|
+
};
|
|
1260
|
+
if (meta.author) itemInput.author = meta.author;
|
|
1261
|
+
if (summary) itemInput.summary = summary;
|
|
1262
|
+
if (meta.status !== void 0) itemInput.status = meta.status;
|
|
1263
|
+
if (meta.category) itemInput.category = meta.category;
|
|
1264
|
+
if (genres.length > 0) itemInput.genres = genres;
|
|
1265
|
+
if (latestChapter) itemInput.latestChapter = latestChapter;
|
|
1266
|
+
if (latestChapterId) itemInput.latestChapterId = latestChapterId;
|
|
1267
|
+
if (meta.updatedAt) itemInput.updatedAt = meta.updatedAt;
|
|
1268
|
+
items.push(buildExploreNovelItem(itemInput));
|
|
1269
|
+
});
|
|
1270
|
+
const pageMatch = cleanInlineText($("#pagestats").text()).match(/(\d+)\s*\/\s*(\d+)/);
|
|
1271
|
+
if (!pageMatch) {
|
|
1272
|
+
if (items.length === 0) return {
|
|
1273
|
+
platform: "linovelib",
|
|
1274
|
+
items: [],
|
|
1275
|
+
page,
|
|
1276
|
+
totalPages: 1,
|
|
1277
|
+
hasNextPage: false
|
|
1278
|
+
};
|
|
1279
|
+
return {
|
|
1280
|
+
platform: "linovelib",
|
|
1281
|
+
items,
|
|
1282
|
+
page,
|
|
1283
|
+
totalPages: page,
|
|
1284
|
+
hasNextPage: false
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
const parsedTotalPages = Number(pageMatch[2]);
|
|
1288
|
+
const totalPages = Number.isInteger(parsedTotalPages) && parsedTotalPages >= 1 ? parsedTotalPages : 1;
|
|
1289
|
+
return {
|
|
1290
|
+
platform: "linovelib",
|
|
1291
|
+
items,
|
|
1292
|
+
page,
|
|
1293
|
+
totalPages,
|
|
1294
|
+
hasNextPage: items.length > 0 && page < totalPages
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
async function getCatalog(options, queue) {
|
|
1298
|
+
const normalized = normalizeCatalogOptions(options);
|
|
1299
|
+
const url = buildCatalogUrl(normalized);
|
|
1300
|
+
return parseCatalogHtml(await queue.fetchPage(url), normalized.page);
|
|
1301
|
+
}
|
|
1302
|
+
// src/explore/home.ts
|
|
1303
|
+
function deduplicateItemsById(items) {
|
|
1304
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1305
|
+
const result = [];
|
|
1306
|
+
for (const item of items) {
|
|
1307
|
+
if (seen.has(item.id)) continue;
|
|
1308
|
+
seen.add(item.id);
|
|
1309
|
+
result.push(item);
|
|
1310
|
+
}
|
|
1311
|
+
return result;
|
|
1312
|
+
}
|
|
1313
|
+
function extractChannelSlugFromHref(href) {
|
|
1314
|
+
if (!href) return null;
|
|
1315
|
+
const slug = href.trim().match(/\/wenku\/([a-z]+)\/1\.html(?:[?#]|$)/)?.[1];
|
|
1316
|
+
return slug && isValidLinovelibChannel(slug) ? slug : null;
|
|
1317
|
+
}
|
|
1318
|
+
function parseMoreTarget(href) {
|
|
1319
|
+
if (!href) return;
|
|
1320
|
+
const trimmed = href.trim();
|
|
1321
|
+
const channelSlug = extractChannelSlugFromHref(trimmed);
|
|
1322
|
+
if (channelSlug) return {
|
|
1323
|
+
type: "channel",
|
|
1324
|
+
params: { channel: channelSlug }
|
|
1325
|
+
};
|
|
1326
|
+
const rankingMatch = trimmed.match(/\/(top|topfull)\/([a-z]+)\/\d+\.html/);
|
|
1327
|
+
if (rankingMatch) {
|
|
1328
|
+
const isFull = rankingMatch[1] === "topfull";
|
|
1329
|
+
const rank = rankingMatch[2] ?? "";
|
|
1330
|
+
if (isValidLinovelibRanking(rank, isFull)) return {
|
|
1331
|
+
type: "ranking",
|
|
1332
|
+
params: {
|
|
1333
|
+
rank,
|
|
1334
|
+
full: String(isFull)
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
const catalogMatch = trimmed.match(/\/wenku\/([a-z]+)_(\d+)_(\d+)_(\d+)_(\d+)_\d+_\d+_(\d+)_\d+_(\d+)\.html/);
|
|
1339
|
+
if (catalogMatch) {
|
|
1340
|
+
const [, sort = "lastupdate", tag = "0", progress = "0", anime = "0", region = "0", words = "0", updated = "0"] = catalogMatch;
|
|
1341
|
+
if (sort === "lastupdate" && tag === "0" && progress === "0" && anime === "0" && region === "0" && words === "0" && updated === "0") return {
|
|
1342
|
+
type: "ranking",
|
|
1343
|
+
params: {
|
|
1344
|
+
rank: "lastupdate",
|
|
1345
|
+
full: "false"
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
return {
|
|
1349
|
+
type: "catalog",
|
|
1350
|
+
params: {
|
|
1351
|
+
sort,
|
|
1352
|
+
region,
|
|
1353
|
+
tag,
|
|
1354
|
+
progress,
|
|
1355
|
+
anime,
|
|
1356
|
+
words,
|
|
1357
|
+
updated
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
function parseFeaturedSection($, $root) {
|
|
1363
|
+
const $tpic = $root.is("#index_tpic") ? $root : $root.find("#index_tpic").first();
|
|
1364
|
+
if ($tpic.length === 0) return null;
|
|
1365
|
+
const coverMap = /* @__PURE__ */ new Map();
|
|
1366
|
+
const titleFallbackMap = /* @__PURE__ */ new Map();
|
|
1367
|
+
$tpic.find("#index_tpic_big a").each((_, el) => {
|
|
1368
|
+
const $a = $(el);
|
|
1369
|
+
const id = extractNovelIdFromHref($a.attr("href"));
|
|
1370
|
+
if (!id) return;
|
|
1371
|
+
const $img = $a.find("img").first();
|
|
1372
|
+
coverMap.set(id, extractImgCoverUrl(id, $img));
|
|
1373
|
+
const alt = cleanInlineText($img.attr("alt"));
|
|
1374
|
+
if (alt) titleFallbackMap.set(id, alt);
|
|
1375
|
+
});
|
|
1376
|
+
const items = [];
|
|
1377
|
+
$tpic.find("#index_tpic_binfo .index_tpic_info").each((_, el) => {
|
|
1378
|
+
const $info = $(el);
|
|
1379
|
+
const $titleLink = $info.find("h3 a.title, h3 a").first();
|
|
1380
|
+
const id = extractNovelIdFromHref($titleLink.attr("href"));
|
|
1381
|
+
if (!id) return;
|
|
1382
|
+
const title = cleanInlineText($titleLink.text()) || cleanInlineText($titleLink.attr("title")) || titleFallbackMap.get(id) || "";
|
|
1383
|
+
if (!title) return;
|
|
1384
|
+
let author = cleanInlineText($info.find(".author a").first().text());
|
|
1385
|
+
if (!author) {
|
|
1386
|
+
const $authorClone = $info.find(".author").first().clone();
|
|
1387
|
+
$authorClone.find("span").remove();
|
|
1388
|
+
author = cleanInlineText($authorClone.text());
|
|
1389
|
+
}
|
|
1390
|
+
const $cateLink = $info.find(".cate a").first();
|
|
1391
|
+
const channelSlug = extractChannelSlugFromHref($cateLink.attr("href"));
|
|
1392
|
+
const category = channelSlug ? getLinovelibChannelOption(channelSlug)?.label : void 0;
|
|
1393
|
+
const rawGenresText = cleanInlineText($cateLink.text());
|
|
1394
|
+
const genres = rawGenresText && rawGenresText !== category && !rawGenresText.startsWith("[") ? rawGenresText.split(/\s+/).filter((g) => g.length > 0) : [];
|
|
1395
|
+
const summary = cleanBlockText($info.find("p.info").text()) || void 0;
|
|
1396
|
+
const $chapLink = $info.find("p.chapter a").first();
|
|
1397
|
+
const latestChapter = cleanInlineText($chapLink.text()) || void 0;
|
|
1398
|
+
const latestChapterId = extractChapterIdFromHref($chapLink.attr("href"), id) ?? void 0;
|
|
1399
|
+
const input = {
|
|
1400
|
+
id,
|
|
1401
|
+
title,
|
|
1402
|
+
coverUrl: coverMap.get(id) ?? resolveDesktopCoverUrl(id)
|
|
1403
|
+
};
|
|
1404
|
+
if (author) input.author = author;
|
|
1405
|
+
if (summary) input.summary = summary;
|
|
1406
|
+
if (category) input.category = category;
|
|
1407
|
+
if (genres.length > 0) input.genres = genres;
|
|
1408
|
+
if (latestChapter) input.latestChapter = latestChapter;
|
|
1409
|
+
if (latestChapterId) input.latestChapterId = latestChapterId;
|
|
1410
|
+
items.push(buildExploreNovelItem(input));
|
|
1411
|
+
});
|
|
1412
|
+
if (items.length === 0 && coverMap.size > 0) for (const [id, coverUrl] of coverMap.entries()) {
|
|
1413
|
+
const title = titleFallbackMap.get(id);
|
|
1414
|
+
if (title) items.push(buildExploreNovelItem({
|
|
1415
|
+
id,
|
|
1416
|
+
title,
|
|
1417
|
+
coverUrl
|
|
1418
|
+
}));
|
|
1419
|
+
}
|
|
1420
|
+
const deduped = deduplicateItemsById(items);
|
|
1421
|
+
if (deduped.length === 0) return null;
|
|
1422
|
+
return {
|
|
1423
|
+
id: "featured",
|
|
1424
|
+
title: "焦点推荐",
|
|
1425
|
+
layout: "featured",
|
|
1426
|
+
items: deduped
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
function extractMindBookItems($, $cards) {
|
|
1430
|
+
const items = [];
|
|
1431
|
+
$cards.each((_, el) => {
|
|
1432
|
+
const $card = $(el);
|
|
1433
|
+
const $nameLink = $card.find(".bookname a").first();
|
|
1434
|
+
const $imgLink = $card.find(".imgbox a").first();
|
|
1435
|
+
const $fallbackLink = $card.find("a[href*='/novel/']").first();
|
|
1436
|
+
const id = extractNovelIdFromHref($nameLink.attr("href")) ?? extractNovelIdFromHref($imgLink.attr("href")) ?? extractNovelIdFromHref($fallbackLink.attr("href"));
|
|
1437
|
+
if (!id) return;
|
|
1438
|
+
const $img = $card.find(".imgbox img, img").first();
|
|
1439
|
+
const title = cleanInlineText($nameLink.text()) || cleanInlineText($card.find(".bookname").text()) || cleanInlineText($img.attr("alt")) || cleanInlineText($fallbackLink.text());
|
|
1440
|
+
if (!title) return;
|
|
1441
|
+
const coverUrl = extractImgCoverUrl(id, $img);
|
|
1442
|
+
const summary = cleanBlockText($card.find("p.info").text()) || void 0;
|
|
1443
|
+
const author = cleanInlineText($card.find(".author").text()) || void 0;
|
|
1444
|
+
const category = cleanInlineText($card.find(".updatenum, .cate").first().text()).replace(/^\[|\]$/g, "") || void 0;
|
|
1445
|
+
const input = {
|
|
1446
|
+
id,
|
|
1447
|
+
title,
|
|
1448
|
+
coverUrl
|
|
1449
|
+
};
|
|
1450
|
+
if (author) input.author = author;
|
|
1451
|
+
if (summary) input.summary = summary;
|
|
1452
|
+
if (category) input.category = category;
|
|
1453
|
+
items.push(buildExploreNovelItem(input));
|
|
1454
|
+
});
|
|
1455
|
+
return items;
|
|
1456
|
+
}
|
|
1457
|
+
function extractSwiperItems($, $swipers) {
|
|
1458
|
+
const items = [];
|
|
1459
|
+
$swipers.each((_, swiperEl) => {
|
|
1460
|
+
const $swiper = $(swiperEl);
|
|
1461
|
+
const coverMap = /* @__PURE__ */ new Map();
|
|
1462
|
+
const titleMap = /* @__PURE__ */ new Map();
|
|
1463
|
+
$swiper.find("li.swiper-item").each((__, liEl) => {
|
|
1464
|
+
const $li = $(liEl);
|
|
1465
|
+
const id = extractNovelIdFromHref($li.attr("data-url"));
|
|
1466
|
+
if (!id) return;
|
|
1467
|
+
const $img = $li.find("img").first();
|
|
1468
|
+
coverMap.set(id, extractImgCoverUrl(id, $img));
|
|
1469
|
+
const liTitle = cleanInlineText($li.attr("title")) || cleanInlineText($img.attr("alt"));
|
|
1470
|
+
if (liTitle) titleMap.set(id, liTitle);
|
|
1471
|
+
});
|
|
1472
|
+
const $infoCards = $swiper.find(".swiper-book .itemInfo");
|
|
1473
|
+
if ($infoCards.length > 0) $infoCards.each((__, infoEl) => {
|
|
1474
|
+
const $info = $(infoEl);
|
|
1475
|
+
const $nameLink = $info.find("a.name, a[href*='/novel/']").first();
|
|
1476
|
+
const id = extractNovelIdFromHref($nameLink.attr("href"));
|
|
1477
|
+
if (!id) return;
|
|
1478
|
+
const title = cleanInlineText($nameLink.text()) || cleanInlineText($nameLink.attr("title")) || titleMap.get(id) || "";
|
|
1479
|
+
if (!title) return;
|
|
1480
|
+
const author = cleanInlineText($info.find("a.author-text, .author").first().text()) || void 0;
|
|
1481
|
+
const category = cleanInlineText($info.find(".cate-text a").first().text()).replace(/^\[|\]$/g, "") || void 0;
|
|
1482
|
+
const wordCount = cleanInlineText($info.find(".cate-text span").first().text()) || void 0;
|
|
1483
|
+
const summary = cleanBlockText($info.find(".intr-text, .intr").first().text()) || void 0;
|
|
1484
|
+
const input = {
|
|
1485
|
+
id,
|
|
1486
|
+
title,
|
|
1487
|
+
coverUrl: coverMap.get(id) ?? resolveDesktopCoverUrl(id)
|
|
1488
|
+
};
|
|
1489
|
+
if (author) input.author = author;
|
|
1490
|
+
if (summary) input.summary = summary;
|
|
1491
|
+
if (category) input.category = category;
|
|
1492
|
+
if (wordCount) input.wordCount = wordCount;
|
|
1493
|
+
items.push(buildExploreNovelItem(input));
|
|
1494
|
+
});
|
|
1495
|
+
else for (const [id, coverUrl] of coverMap.entries()) {
|
|
1496
|
+
const title = titleMap.get(id);
|
|
1497
|
+
if (title) items.push(buildExploreNovelItem({
|
|
1498
|
+
id,
|
|
1499
|
+
title,
|
|
1500
|
+
coverUrl
|
|
1501
|
+
}));
|
|
1502
|
+
}
|
|
1503
|
+
});
|
|
1504
|
+
return items;
|
|
1505
|
+
}
|
|
1506
|
+
function extractListItems($, $listItems, defaultCategory) {
|
|
1507
|
+
const items = [];
|
|
1508
|
+
$listItems.each((_, liEl) => {
|
|
1509
|
+
const $li = $(liEl);
|
|
1510
|
+
const $novelLinks = $li.find("a[href*='/novel/']").filter((__, aEl) => {
|
|
1511
|
+
return extractNovelIdFromHref($(aEl).attr("href")) !== null;
|
|
1512
|
+
});
|
|
1513
|
+
if ($novelLinks.length === 0) return;
|
|
1514
|
+
const $titleLink = $li.find("a.title").first();
|
|
1515
|
+
const $primaryLink = $titleLink.length > 0 && extractNovelIdFromHref($titleLink.attr("href")) ? $titleLink : $novelLinks.last();
|
|
1516
|
+
const id = extractNovelIdFromHref($primaryLink.attr("href"));
|
|
1517
|
+
if (!id) return;
|
|
1518
|
+
const title = cleanInlineText($primaryLink.text()) || cleanInlineText($primaryLink.attr("title")) || cleanInlineText($li.find("img").first().attr("alt"));
|
|
1519
|
+
if (!title) return;
|
|
1520
|
+
const $img = $li.find(".imgbox img, img").first();
|
|
1521
|
+
const coverUrl = $img.length > 0 ? extractImgCoverUrl(id, $img) : resolveDesktopCoverUrl(id);
|
|
1522
|
+
const author = cleanInlineText($li.find("a.author, a.author2, span.author").first().text()) || void 0;
|
|
1523
|
+
const category = cleanInlineText($li.find("a.cate").first().text()).replace(/^\[|\]$/g, "") || defaultCategory;
|
|
1524
|
+
const input = {
|
|
1525
|
+
id,
|
|
1526
|
+
title,
|
|
1527
|
+
coverUrl
|
|
1528
|
+
};
|
|
1529
|
+
if (author) input.author = author;
|
|
1530
|
+
if (category) input.category = category;
|
|
1531
|
+
items.push(buildExploreNovelItem(input));
|
|
1532
|
+
});
|
|
1533
|
+
return items;
|
|
1534
|
+
}
|
|
1535
|
+
function parseTabListsRankSection($, $tabLists, id, fallbackTitle) {
|
|
1536
|
+
if ($tabLists.length === 0) return null;
|
|
1537
|
+
const $heading = $tabLists.find(".top-title").first();
|
|
1538
|
+
const title = extractHeadingTitle($heading) || fallbackTitle;
|
|
1539
|
+
const more = parseMoreTarget($heading.find(".more a").first().attr("href"));
|
|
1540
|
+
const items = deduplicateItemsById(extractListItems($, $tabLists.find(".lists ul li"))).map((item, idx) => ({
|
|
1541
|
+
...item,
|
|
1542
|
+
rank: idx + 1
|
|
1543
|
+
}));
|
|
1544
|
+
if (items.length === 0) return null;
|
|
1545
|
+
const section = {
|
|
1546
|
+
id,
|
|
1547
|
+
title,
|
|
1548
|
+
layout: "rank",
|
|
1549
|
+
items
|
|
1550
|
+
};
|
|
1551
|
+
if (more) section.more = more;
|
|
1552
|
+
return section;
|
|
1553
|
+
}
|
|
1554
|
+
function extractHeadingTitle($heading) {
|
|
1555
|
+
if ($heading.length === 0) return "";
|
|
1556
|
+
const $titleNode = $heading.children(".title").first().length > 0 ? $heading.children(".title").first() : $heading.find(".title").first();
|
|
1557
|
+
if ($titleNode.length > 0) {
|
|
1558
|
+
const $clone = $titleNode.clone();
|
|
1559
|
+
$clone.find(".more, .compile").remove();
|
|
1560
|
+
return cleanInlineText($clone.text());
|
|
1561
|
+
}
|
|
1562
|
+
const $clone = $heading.clone();
|
|
1563
|
+
$clone.find(".more, .compile").remove();
|
|
1564
|
+
return cleanInlineText($clone.text());
|
|
1565
|
+
}
|
|
1566
|
+
function parseUpdatesSection($, $newChapter, id, fallbackMore) {
|
|
1567
|
+
if ($newChapter.length === 0) return null;
|
|
1568
|
+
const $tabT = $newChapter.find(".title .tabT.active, .title .tabT").first();
|
|
1569
|
+
const $titleClone = ($tabT.length > 0 ? $tabT : $newChapter.find(".title").first()).clone();
|
|
1570
|
+
const moreHref = $newChapter.find(".title .more a").first().attr("href");
|
|
1571
|
+
$titleClone.find(".more").remove();
|
|
1572
|
+
const title = cleanInlineText($titleClone.text()) || "最近更新";
|
|
1573
|
+
const items = [];
|
|
1574
|
+
$newChapter.find(".main_con li, ul li").each((_, liEl) => {
|
|
1575
|
+
const $li = $(liEl);
|
|
1576
|
+
const $bookLink = $li.find("span.bookname a, a[href*='/novel/']").first();
|
|
1577
|
+
const novelId = extractNovelIdFromHref($bookLink.attr("href"));
|
|
1578
|
+
if (!novelId) return;
|
|
1579
|
+
const novelTitle = cleanInlineText($bookLink.text()) || cleanInlineText($bookLink.attr("title"));
|
|
1580
|
+
if (!novelTitle) return;
|
|
1581
|
+
const category = cleanInlineText($li.find("span.kind").text()).replace(/^\[|\]$/g, "") || void 0;
|
|
1582
|
+
const $chapLink = $li.find("span.chap a").first();
|
|
1583
|
+
const latestChapter = cleanInlineText($chapLink.text()) || void 0;
|
|
1584
|
+
const latestChapterId = extractChapterIdFromHref($chapLink.attr("href"), novelId) ?? void 0;
|
|
1585
|
+
const author = cleanInlineText($li.find("span.author").text()) || void 0;
|
|
1586
|
+
const wordCount = cleanInlineText($li.find("span.count").text()) || void 0;
|
|
1587
|
+
const updatedAt = cleanInlineText($li.find("span.time").text()) || void 0;
|
|
1588
|
+
const input = {
|
|
1589
|
+
id: novelId,
|
|
1590
|
+
title: novelTitle,
|
|
1591
|
+
coverUrl: resolveDesktopCoverUrl(novelId)
|
|
1592
|
+
};
|
|
1593
|
+
if (author) input.author = author;
|
|
1594
|
+
if (category) input.category = category;
|
|
1595
|
+
if (latestChapter) input.latestChapter = latestChapter;
|
|
1596
|
+
if (latestChapterId) input.latestChapterId = latestChapterId;
|
|
1597
|
+
if (wordCount) input.wordCount = wordCount;
|
|
1598
|
+
if (updatedAt) input.updatedAt = updatedAt;
|
|
1599
|
+
items.push(buildExploreNovelItem(input));
|
|
1600
|
+
});
|
|
1601
|
+
const deduped = deduplicateItemsById(items);
|
|
1602
|
+
if (deduped.length === 0) return null;
|
|
1603
|
+
const more = parseMoreTarget(moreHref) ?? fallbackMore;
|
|
1604
|
+
const section = {
|
|
1605
|
+
id,
|
|
1606
|
+
title,
|
|
1607
|
+
layout: "updates",
|
|
1608
|
+
items: deduped
|
|
1609
|
+
};
|
|
1610
|
+
if (more) section.more = more;
|
|
1611
|
+
return section;
|
|
1612
|
+
}
|
|
1613
|
+
function parseDesktopRootHome($) {
|
|
1614
|
+
const sections = [];
|
|
1615
|
+
const featured = parseFeaturedSection($, $(".pdt40 .top-one-blank-left").first());
|
|
1616
|
+
if (featured) sections.push(featured);
|
|
1617
|
+
const recommendRank = parseTabListsRankSection($, $(".pdt40 .top-one-blank-right .tab-lists").first(), "recommend-rank", "强推榜");
|
|
1618
|
+
if (recommendRank) sections.push(recommendRank);
|
|
1619
|
+
const $firstTwoBlank = $(".top-two-blank").eq(0);
|
|
1620
|
+
const $newBooksBox = $firstTwoBlank.find(".book-blank-box .tab-lists-two").first();
|
|
1621
|
+
const newBooksItems = deduplicateItemsById(extractMindBookItems($, $newBooksBox.find(".mind-showbook .mind-book")));
|
|
1622
|
+
if (newBooksItems.length > 0) sections.push({
|
|
1623
|
+
id: "new-books-featured",
|
|
1624
|
+
title: extractHeadingTitle($newBooksBox.find(".top-title").first()) || "新书精选",
|
|
1625
|
+
layout: "grid",
|
|
1626
|
+
items: newBooksItems
|
|
1627
|
+
});
|
|
1628
|
+
const newBooksRank = parseTabListsRankSection($, $firstTwoBlank.find(".top-two-blank-right .tab-lists").first(), "new-books-rank", "新书榜");
|
|
1629
|
+
if (newBooksRank) sections.push(newBooksRank);
|
|
1630
|
+
const $maleBlank = $(".male-blank").first();
|
|
1631
|
+
const hotItems = deduplicateItemsById(extractSwiperItems($, $maleBlank.find(".pic-blank-scroll .swiper-wrapper")));
|
|
1632
|
+
if (hotItems.length > 0) sections.push({
|
|
1633
|
+
id: "hot-novels",
|
|
1634
|
+
title: extractHeadingTitle($maleBlank.find(".tab-lists-two > .top-title").first()) || "热门小说",
|
|
1635
|
+
layout: "grid",
|
|
1636
|
+
items: hotItems
|
|
1637
|
+
});
|
|
1638
|
+
$maleBlank.find(".cate-blank .cate-cell").each((index, cellEl) => {
|
|
1639
|
+
const $cell = $(cellEl);
|
|
1640
|
+
const $heading = $cell.find(".top-title-two").first();
|
|
1641
|
+
const title = extractHeadingTitle($heading);
|
|
1642
|
+
if (!title) return;
|
|
1643
|
+
const more = parseMoreTarget($heading.find(".more a").first().attr("href"));
|
|
1644
|
+
const channelSlug = more?.type === "channel" ? more.params.channel : void 0;
|
|
1645
|
+
const items = deduplicateItemsById(extractListItems($, $cell.find(".lists ul li"), title));
|
|
1646
|
+
if (items.length === 0) return;
|
|
1647
|
+
const section = {
|
|
1648
|
+
id: channelSlug ? `channel-${channelSlug}` : `channel-grid-${index}`,
|
|
1649
|
+
title,
|
|
1650
|
+
layout: "grid",
|
|
1651
|
+
items
|
|
1652
|
+
};
|
|
1653
|
+
if (more) section.more = more;
|
|
1654
|
+
sections.push(section);
|
|
1655
|
+
});
|
|
1656
|
+
const $secondTwoBlank = $(".top-two-blank").eq(1);
|
|
1657
|
+
const $classicLeft = $secondTwoBlank.find(".top-two-blank-left").first();
|
|
1658
|
+
const classicItems = deduplicateItemsById(extractSwiperItems($, $classicLeft.find(".swiper-wrapper")));
|
|
1659
|
+
if (classicItems.length > 0) sections.push({
|
|
1660
|
+
id: "classic-completed",
|
|
1661
|
+
title: extractHeadingTitle($classicLeft.find(".top-title").first()) || "经典完本",
|
|
1662
|
+
layout: "grid",
|
|
1663
|
+
items: classicItems
|
|
1664
|
+
});
|
|
1665
|
+
const $completedMid = $secondTwoBlank.find(".top-two-blank-mid .tab-lists-two").first();
|
|
1666
|
+
const completedItems = deduplicateItemsById(extractMindBookItems($, $completedMid.find(".mind-showbook .mind-book")));
|
|
1667
|
+
if (completedItems.length > 0) sections.push({
|
|
1668
|
+
id: "completed-recommended",
|
|
1669
|
+
title: extractHeadingTitle($completedMid.find(".top-title").first()) || "完本推荐",
|
|
1670
|
+
layout: "grid",
|
|
1671
|
+
items: completedItems
|
|
1672
|
+
});
|
|
1673
|
+
const hotRank = parseTabListsRankSection($, $secondTwoBlank.find(".top-two-blank-right .tab-lists").first(), "hot-rank", "热点榜");
|
|
1674
|
+
if (hotRank) sections.push(hotRank);
|
|
1675
|
+
const updates = parseUpdatesSection($, $(".new_chapter").first(), "recent-updates", {
|
|
1676
|
+
type: "ranking",
|
|
1677
|
+
params: {
|
|
1678
|
+
rank: "lastupdate",
|
|
1679
|
+
full: "false"
|
|
1680
|
+
}
|
|
1681
|
+
});
|
|
1682
|
+
if (updates) sections.push(updates);
|
|
1683
|
+
return sections;
|
|
1684
|
+
}
|
|
1685
|
+
const MODULE_CONTAINER_SELECTOR = ".tab-lists, .tab-lists-two, .cate-cell, .top-two-blank-left, .new_chapter";
|
|
1686
|
+
function isDirectChildOfContainer($el, containerEl) {
|
|
1687
|
+
const $closest = $el.closest(MODULE_CONTAINER_SELECTOR);
|
|
1688
|
+
return $closest.length > 0 && $closest.get(0) === containerEl;
|
|
1689
|
+
}
|
|
1690
|
+
function mergeSectionIntoList(sections, titleIndexMap, incoming) {
|
|
1691
|
+
const key = `${incoming.layout}:${incoming.title}`;
|
|
1692
|
+
const existingIndex = titleIndexMap.get(key);
|
|
1693
|
+
if (existingIndex === void 0) {
|
|
1694
|
+
titleIndexMap.set(key, sections.length);
|
|
1695
|
+
sections.push(incoming);
|
|
1696
|
+
return;
|
|
1697
|
+
}
|
|
1698
|
+
const existing = sections[existingIndex];
|
|
1699
|
+
if (!existing) return;
|
|
1700
|
+
const mergedItems = deduplicateItemsById([...existing.items, ...incoming.items]);
|
|
1701
|
+
existing.items = existing.layout === "rank" ? mergedItems.map((item, idx) => ({
|
|
1702
|
+
...item,
|
|
1703
|
+
rank: idx + 1
|
|
1704
|
+
})) : mergedItems;
|
|
1705
|
+
if (!existing.more && incoming.more) existing.more = incoming.more;
|
|
1706
|
+
}
|
|
1707
|
+
function parseChannelPageSections($, channel) {
|
|
1708
|
+
const sections = [];
|
|
1709
|
+
const titleIndexMap = /* @__PURE__ */ new Map();
|
|
1710
|
+
const featured = parseFeaturedSection($, $("#index_tpic").first());
|
|
1711
|
+
if (featured) mergeSectionIntoList(sections, titleIndexMap, featured);
|
|
1712
|
+
let sectionSeq = 0;
|
|
1713
|
+
$(".top-title, .top-title-two, .new_chapter").each((_, el) => {
|
|
1714
|
+
const $el = $(el);
|
|
1715
|
+
if ($el.hasClass("new_chapter")) {
|
|
1716
|
+
const updates = parseUpdatesSection($, $el, `${channel}-updates-${sectionSeq++}`, {
|
|
1717
|
+
type: "ranking",
|
|
1718
|
+
params: {
|
|
1719
|
+
rank: "lastupdate",
|
|
1720
|
+
full: "false"
|
|
1721
|
+
}
|
|
1722
|
+
});
|
|
1723
|
+
if (updates) mergeSectionIntoList(sections, titleIndexMap, updates);
|
|
1724
|
+
return;
|
|
1725
|
+
}
|
|
1726
|
+
if ($el.closest(".new_chapter").length > 0) return;
|
|
1727
|
+
const $container = $el.parent();
|
|
1728
|
+
const containerEl = $container.get(0);
|
|
1729
|
+
if (!containerEl) return;
|
|
1730
|
+
const title = extractHeadingTitle($el);
|
|
1731
|
+
if (!title) return;
|
|
1732
|
+
const more = parseMoreTarget($el.find(".more a").first().attr("href"));
|
|
1733
|
+
const directSwipers = $container.find(".swiper-wrapper").filter((__, node) => isDirectChildOfContainer($(node), containerEl));
|
|
1734
|
+
const directMindBooks = $container.find(".mind-book").filter((__, node) => isDirectChildOfContainer($(node), containerEl));
|
|
1735
|
+
const directListItems = $container.find(".lists ul li").filter((__, node) => isDirectChildOfContainer($(node), containerEl));
|
|
1736
|
+
const collected = [
|
|
1737
|
+
...extractSwiperItems($, directSwipers),
|
|
1738
|
+
...extractMindBookItems($, directMindBooks),
|
|
1739
|
+
...extractListItems($, directListItems)
|
|
1740
|
+
];
|
|
1741
|
+
const layout = $container.hasClass("tab-lists") || title.endsWith("榜") || directListItems.find(".list_icon").length > 0 ? "rank" : "grid";
|
|
1742
|
+
let items = deduplicateItemsById(collected);
|
|
1743
|
+
if (items.length === 0) return;
|
|
1744
|
+
if (layout === "rank") items = items.map((item, idx) => ({
|
|
1745
|
+
...item,
|
|
1746
|
+
rank: idx + 1
|
|
1747
|
+
}));
|
|
1748
|
+
const section = {
|
|
1749
|
+
id: `${channel}-section-${sectionSeq++}`,
|
|
1750
|
+
title,
|
|
1751
|
+
layout,
|
|
1752
|
+
items
|
|
1753
|
+
};
|
|
1754
|
+
if (more) section.more = more;
|
|
1755
|
+
mergeSectionIntoList(sections, titleIndexMap, section);
|
|
1756
|
+
});
|
|
1757
|
+
return sections;
|
|
1758
|
+
}
|
|
1759
|
+
function parseHomeHtml(html, channel = "home") {
|
|
1760
|
+
if (!isValidLinovelibChannel(channel)) throw new Error(`Invalid linovelib explore channel: ${channel}`);
|
|
1761
|
+
const $ = load(html);
|
|
1762
|
+
return {
|
|
1763
|
+
platform: "linovelib",
|
|
1764
|
+
channel,
|
|
1765
|
+
title: getLinovelibChannelOption(channel)?.label ?? "全站首页",
|
|
1766
|
+
sections: channel === "home" ? parseDesktopRootHome($) : parseChannelPageSections($, channel)
|
|
1767
|
+
};
|
|
1768
|
+
}
|
|
1769
|
+
async function getExploreHome(channel, queue) {
|
|
1770
|
+
const resolvedChannel = channel ?? "home";
|
|
1771
|
+
if (!isValidLinovelibChannel(resolvedChannel)) throw new Error(`Invalid linovelib explore channel: ${resolvedChannel}`);
|
|
1772
|
+
const url = resolvedChannel === "home" ? `${LINOVELIB_DESKTOP_BASE}/` : `${LINOVELIB_DESKTOP_BASE}/wenku/${resolvedChannel}/1.html`;
|
|
1773
|
+
return parseHomeHtml(await queue.fetchPage(url), resolvedChannel);
|
|
1774
|
+
}
|
|
1775
|
+
// src/explore/rankings.ts
|
|
1776
|
+
const RANKINGS_PAGE_SIZE = 30;
|
|
1777
|
+
function buildRankingsUrl(rank, full, page) {
|
|
1778
|
+
if (!isValidLinovelibRanking(rank, full)) throw new Error(`Invalid linovelib ranking combination: rank=${rank}, full=${String(full)}`);
|
|
1779
|
+
if (!Number.isInteger(page) || page < 1) throw new Error(`Invalid linovelib ranking page: ${page}`);
|
|
1780
|
+
return `${LINOVELIB_DESKTOP_BASE}/${full ? "topfull" : "top"}/${rank}/${page}.html`;
|
|
1781
|
+
}
|
|
1782
|
+
function parseRankingsHtml(html, page) {
|
|
1783
|
+
const $ = load(html);
|
|
1784
|
+
const items = [];
|
|
1785
|
+
$(".rank_d_list").each((index, el) => {
|
|
1786
|
+
const $el = $(el);
|
|
1787
|
+
const $nameLink = $el.find(".rank_d_b_name a").first();
|
|
1788
|
+
const $imgLink = $el.find(".rank_d_book_img a").first();
|
|
1789
|
+
const id = extractNovelIdFromHref($nameLink.attr("href")) ?? extractNovelIdFromHref($imgLink.attr("href"));
|
|
1790
|
+
if (!id) return;
|
|
1791
|
+
const title = cleanInlineText($nameLink.text()) || cleanInlineText($el.find(".rank_d_b_name").attr("title")) || cleanInlineText($el.find(".rank_d_book_img img").attr("alt"));
|
|
1792
|
+
if (!title) return;
|
|
1793
|
+
const coverUrl = extractImgCoverUrl(id, $el.find(".rank_d_book_img img").first());
|
|
1794
|
+
const cateParts = $el.find(".rank_d_b_cate").text().split("|").map((part) => cleanInlineText(part));
|
|
1795
|
+
const author = cateParts[0] || void 0;
|
|
1796
|
+
const category = cateParts[1] || void 0;
|
|
1797
|
+
const statusText = cateParts[2];
|
|
1798
|
+
const status = statusText ? parseNovelStatusText(statusText) : void 0;
|
|
1799
|
+
const summary = cleanBlockText($el.find(".rank_d_b_info").text()) || void 0;
|
|
1800
|
+
const $lastLink = $el.find(".rank_d_b_last a").first();
|
|
1801
|
+
const $clonedLast = $lastLink.clone();
|
|
1802
|
+
$clonedLast.find(".rank_d_lastchapter").remove();
|
|
1803
|
+
const latestChapter = cleanInlineText($clonedLast.text()) || void 0;
|
|
1804
|
+
const latestChapterId = extractChapterIdFromHref($lastLink.attr("href"), id) ?? void 0;
|
|
1805
|
+
const updatedAt = cleanInlineText($el.find(".rank_d_b_time").text()) || void 0;
|
|
1806
|
+
const itemInput = {
|
|
1807
|
+
id,
|
|
1808
|
+
title,
|
|
1809
|
+
coverUrl,
|
|
1810
|
+
rank: (page - 1) * RANKINGS_PAGE_SIZE + index + 1
|
|
1811
|
+
};
|
|
1812
|
+
if (author) itemInput.author = author;
|
|
1813
|
+
if (summary) itemInput.summary = summary;
|
|
1814
|
+
if (status !== void 0) itemInput.status = status;
|
|
1815
|
+
if (category) itemInput.category = category;
|
|
1816
|
+
if (latestChapter) itemInput.latestChapter = latestChapter;
|
|
1817
|
+
if (latestChapterId) itemInput.latestChapterId = latestChapterId;
|
|
1818
|
+
if (updatedAt) itemInput.updatedAt = updatedAt;
|
|
1819
|
+
items.push(buildExploreNovelItem(itemInput));
|
|
1820
|
+
});
|
|
1821
|
+
return {
|
|
1822
|
+
platform: "linovelib",
|
|
1823
|
+
items,
|
|
1824
|
+
page,
|
|
1825
|
+
hasNextPage: items.length >= RANKINGS_PAGE_SIZE
|
|
1826
|
+
};
|
|
1827
|
+
}
|
|
1828
|
+
async function getRankings(options, queue) {
|
|
1829
|
+
const full = options.full ?? false;
|
|
1830
|
+
const page = options.page ?? 1;
|
|
1831
|
+
const url = buildRankingsUrl(options.rank, full, page);
|
|
1832
|
+
return parseRankingsHtml(await queue.fetchPage(url), page);
|
|
1833
|
+
}
|
|
490
1834
|
// src/queue.ts
|
|
491
1835
|
/**
|
|
492
1836
|
* Simple backoff strategy for request rate limiting
|
|
@@ -663,6 +2007,9 @@ const DEFAULT_MEDIA_CLOUDFLARE_BACKOFF_MS = [
|
|
|
663
2007
|
15e3
|
|
664
2008
|
];
|
|
665
2009
|
const DEFAULT_MEDIA_RETRIES = 4;
|
|
2010
|
+
const DEFAULT_MEDIA_TIMEOUT_MS = 25e3;
|
|
2011
|
+
const DEFAULT_MEDIA_CONNECT_TIMEOUT_MS = 1e4;
|
|
2012
|
+
const DEFAULT_MEDIA_NETWORK_RETRIES = 2;
|
|
666
2013
|
function computeSecFetchSite(targetUrl, referer) {
|
|
667
2014
|
try {
|
|
668
2015
|
const target = new URL(targetUrl);
|
|
@@ -688,6 +2035,9 @@ var NovelMediaQueue = class {
|
|
|
688
2035
|
normalDelayMaxMs;
|
|
689
2036
|
cloudflareBackoffMs;
|
|
690
2037
|
retries;
|
|
2038
|
+
timeoutMs;
|
|
2039
|
+
connectionTimeoutMs;
|
|
2040
|
+
networkRetries;
|
|
691
2041
|
constructor(client, logger, options) {
|
|
692
2042
|
this.queue = new PQueue({ concurrency: 1 });
|
|
693
2043
|
this.client = client;
|
|
@@ -696,11 +2046,14 @@ var NovelMediaQueue = class {
|
|
|
696
2046
|
this.normalDelayMaxMs = Math.max(this.normalDelayMinMs, options?.normalDelayMaxMs ?? DEFAULT_MEDIA_NORMAL_DELAY_MAX_MS);
|
|
697
2047
|
this.cloudflareBackoffMs = options?.cloudflareBackoffMs && options.cloudflareBackoffMs.length > 0 ? options.cloudflareBackoffMs : DEFAULT_MEDIA_CLOUDFLARE_BACKOFF_MS;
|
|
698
2048
|
this.retries = options?.retries ?? DEFAULT_MEDIA_RETRIES;
|
|
2049
|
+
this.timeoutMs = options?.timeoutMs ?? DEFAULT_MEDIA_TIMEOUT_MS;
|
|
2050
|
+
this.connectionTimeoutMs = options?.connectionTimeoutMs ?? DEFAULT_MEDIA_CONNECT_TIMEOUT_MS;
|
|
2051
|
+
this.networkRetries = options?.networkRetries ?? DEFAULT_MEDIA_NETWORK_RETRIES;
|
|
699
2052
|
this.queue.addEventListener("add", () => {
|
|
700
|
-
this.logger?.debug(`[NovelMediaQueue] 任务已添加,当前排队数: ${this.queue.size} (
|
|
2053
|
+
this.logger?.debug(`[NovelMediaQueue] 任务已添加,当前排队数: ${this.queue.size} (执行中: ${this.queue.pending})`);
|
|
701
2054
|
});
|
|
702
2055
|
this.queue.addEventListener("next", () => {
|
|
703
|
-
this.logger?.debug(`[NovelMediaQueue]
|
|
2056
|
+
this.logger?.debug(`[NovelMediaQueue] 任务已结束,剩余排队数: ${this.queue.size} (执行中: ${this.queue.pending})`);
|
|
704
2057
|
});
|
|
705
2058
|
}
|
|
706
2059
|
async _sleep(ms) {
|
|
@@ -711,9 +2064,13 @@ var NovelMediaQueue = class {
|
|
|
711
2064
|
}
|
|
712
2065
|
async fetchImage(url, referer = "https://www.linovelib.com/") {
|
|
713
2066
|
const existing = this.inFlight.get(url);
|
|
714
|
-
if (existing)
|
|
2067
|
+
if (existing) {
|
|
2068
|
+
this.logger?.debug(`[NovelMediaQueue] 复用在途图片请求: ${url}`);
|
|
2069
|
+
return await existing;
|
|
2070
|
+
}
|
|
715
2071
|
const taskPromise = (async () => {
|
|
716
2072
|
return await this.queue.add(async () => {
|
|
2073
|
+
const startedAt = Date.now();
|
|
717
2074
|
const cooldownWait = this.cooldownUntil - Date.now();
|
|
718
2075
|
if (cooldownWait > 0) {
|
|
719
2076
|
this.logger?.debug(`[NovelMediaQueue] 等待 Cloudflare 冷却 ${Math.floor(cooldownWait)}ms`);
|
|
@@ -726,6 +2083,7 @@ var NovelMediaQueue = class {
|
|
|
726
2083
|
this.logger?.debug(`[NovelMediaQueue] 请求过快,等待 ${Math.floor(waitTime)}ms`);
|
|
727
2084
|
await this._sleep(waitTime);
|
|
728
2085
|
}
|
|
2086
|
+
this.logger?.debug(`[NovelMediaQueue] 开始获取图片: ${url} (排队数: ${this.queue.size})`);
|
|
729
2087
|
const headers = {
|
|
730
2088
|
Referer: referer,
|
|
731
2089
|
Accept: "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
|
|
@@ -733,6 +2091,7 @@ var NovelMediaQueue = class {
|
|
|
733
2091
|
"Sec-Fetch-Mode": "no-cors",
|
|
734
2092
|
"Sec-Fetch-Site": computeSecFetchSite(url, referer)
|
|
735
2093
|
};
|
|
2094
|
+
const canRetryNetwork = (ctx) => defaultRetryPolicy(ctx) && ctx.attemptNumber <= this.networkRetries && ctx.retriesLeft > 0;
|
|
736
2095
|
const retry = {
|
|
737
2096
|
retries: this.retries,
|
|
738
2097
|
factor: 2,
|
|
@@ -751,7 +2110,7 @@ var NovelMediaQueue = class {
|
|
|
751
2110
|
return;
|
|
752
2111
|
}
|
|
753
2112
|
if (defaultRetryPolicy(ctx)) {
|
|
754
|
-
if (ctx
|
|
2113
|
+
if (canRetryNetwork(ctx)) {
|
|
755
2114
|
const delayMs = Math.min(1e3 * 2 ** Math.max(ctx.attemptNumber - 1, 0), 8e3);
|
|
756
2115
|
this.logger?.warn(`[NovelMediaQueue] 图片请求异常 (${url}),第 ${ctx.attemptNumber} 次失败,等待 ${delayMs}ms 后重试: ${ctx.error.message}`);
|
|
757
2116
|
await this._sleep(delayMs);
|
|
@@ -759,15 +2118,23 @@ var NovelMediaQueue = class {
|
|
|
759
2118
|
}
|
|
760
2119
|
},
|
|
761
2120
|
shouldRetry: async (ctx) => {
|
|
762
|
-
return defaultRetryPolicy(ctx)
|
|
2121
|
+
return ctx.error instanceof CloudflareBlockError || defaultRetryPolicy(ctx) && ctx.attemptNumber <= this.networkRetries;
|
|
763
2122
|
}
|
|
764
2123
|
};
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
2124
|
+
try {
|
|
2125
|
+
const response = await this.client.binary(url, {
|
|
2126
|
+
headers,
|
|
2127
|
+
retry,
|
|
2128
|
+
timeout: this.timeoutMs,
|
|
2129
|
+
connectionTimeout: this.connectionTimeoutMs
|
|
2130
|
+
});
|
|
2131
|
+
this.lastFetchTime = Date.now();
|
|
2132
|
+
this.logger?.debug(`[NovelMediaQueue] 图片获取成功 (${Date.now() - startedAt}ms, ${response.data.length}B, ${response.mimeType}): ${url}`);
|
|
2133
|
+
return response;
|
|
2134
|
+
} catch (error) {
|
|
2135
|
+
this.logger?.warn(`[NovelMediaQueue] 图片获取最终失败 (${Date.now() - startedAt}ms, ${url}): ${error instanceof Error ? error.message : String(error)}`);
|
|
2136
|
+
throw error;
|
|
2137
|
+
}
|
|
771
2138
|
});
|
|
772
2139
|
})().finally(() => {
|
|
773
2140
|
this.inFlight.delete(url);
|
|
@@ -776,6 +2143,69 @@ var NovelMediaQueue = class {
|
|
|
776
2143
|
return await taskPromise;
|
|
777
2144
|
}
|
|
778
2145
|
};
|
|
2146
|
+
const DEFAULT_EXPLORE_DELAY_MIN_MS = 300;
|
|
2147
|
+
const DEFAULT_EXPLORE_RETRIES = 2;
|
|
2148
|
+
var NovelExploreQueue = class {
|
|
2149
|
+
queue;
|
|
2150
|
+
client;
|
|
2151
|
+
logger;
|
|
2152
|
+
nextAvailableTime = 0;
|
|
2153
|
+
constructor(client, logger) {
|
|
2154
|
+
this.queue = new PQueue({ concurrency: 2 });
|
|
2155
|
+
this.client = client;
|
|
2156
|
+
this.logger = logger;
|
|
2157
|
+
this.queue.addEventListener("add", () => {
|
|
2158
|
+
this.logger?.debug(`[NovelExploreQueue] 任务已添加,当前排队数: ${this.queue.size} (执行中: ${this.queue.pending})`);
|
|
2159
|
+
});
|
|
2160
|
+
this.queue.addEventListener("next", () => {
|
|
2161
|
+
this.logger?.debug(`[NovelExploreQueue] 任务已结束,剩余排队数: ${this.queue.size} (执行中: ${this.queue.pending})`);
|
|
2162
|
+
});
|
|
2163
|
+
}
|
|
2164
|
+
async _sleep(ms) {
|
|
2165
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2166
|
+
}
|
|
2167
|
+
getThrottleDelay() {
|
|
2168
|
+
return DEFAULT_EXPLORE_DELAY_MIN_MS + Math.random() * 300;
|
|
2169
|
+
}
|
|
2170
|
+
async fetchPage(url) {
|
|
2171
|
+
return await this.queue.add(async () => {
|
|
2172
|
+
const delay = this.getThrottleDelay();
|
|
2173
|
+
const now = Date.now();
|
|
2174
|
+
const scheduledAt = Math.max(now, this.nextAvailableTime);
|
|
2175
|
+
this.nextAvailableTime = scheduledAt + delay;
|
|
2176
|
+
const waitTime = scheduledAt - now;
|
|
2177
|
+
if (waitTime > 0) {
|
|
2178
|
+
this.logger?.debug(`[NovelExploreQueue] 请求过快,等待 ${Math.floor(waitTime)}ms`);
|
|
2179
|
+
await this._sleep(waitTime);
|
|
2180
|
+
}
|
|
2181
|
+
this.logger?.debug(`[NovelExploreQueue] 开始抓取页面: ${url}`);
|
|
2182
|
+
const retry = {
|
|
2183
|
+
retries: DEFAULT_EXPLORE_RETRIES,
|
|
2184
|
+
factor: 2,
|
|
2185
|
+
minRetryDelayMs: 500,
|
|
2186
|
+
maxRetryDelayMs: 3e3,
|
|
2187
|
+
randomize: true,
|
|
2188
|
+
onFailedAttempt: async (ctx) => {
|
|
2189
|
+
if (ctx.error instanceof CloudflareBlockError) {
|
|
2190
|
+
this.logger?.warn(`[NovelExploreQueue] 页面触发 Cloudflare 拦截 (${url}): ${ctx.error.message}`);
|
|
2191
|
+
return;
|
|
2192
|
+
}
|
|
2193
|
+
if (defaultRetryPolicy(ctx)) {
|
|
2194
|
+
if (ctx.retriesLeft > 0) this.logger?.warn(`[NovelExploreQueue] 页面请求异常 (${url}),第 ${ctx.attemptNumber} 次失败,即将重试: ${ctx.error.message}`);
|
|
2195
|
+
else this.logger?.error(`[NovelExploreQueue] 页面请求重试次数已达上限 (${ctx.attemptNumber} 次, ${url}): ${ctx.error.message}`);
|
|
2196
|
+
}
|
|
2197
|
+
},
|
|
2198
|
+
shouldRetry: async (ctx) => {
|
|
2199
|
+
if (ctx.error instanceof CloudflareBlockError) return false;
|
|
2200
|
+
return defaultRetryPolicy(ctx);
|
|
2201
|
+
}
|
|
2202
|
+
};
|
|
2203
|
+
const response = await this.client.text(url, { retry });
|
|
2204
|
+
this.logger?.debug(`[NovelExploreQueue] 页面获取成功: ${url}`);
|
|
2205
|
+
return response.data ?? "";
|
|
2206
|
+
});
|
|
2207
|
+
}
|
|
2208
|
+
};
|
|
779
2209
|
// src/search/common.ts
|
|
780
2210
|
function parseSearchHtml($) {
|
|
781
2211
|
const results = [];
|
|
@@ -1179,6 +2609,7 @@ var LinovelibClient = class {
|
|
|
1179
2609
|
novelChapterQueue;
|
|
1180
2610
|
novelInfoQueue;
|
|
1181
2611
|
novelMediaQueue;
|
|
2612
|
+
novelExploreQueue;
|
|
1182
2613
|
searchSession;
|
|
1183
2614
|
options;
|
|
1184
2615
|
logger;
|
|
@@ -1235,6 +2666,7 @@ var LinovelibClient = class {
|
|
|
1235
2666
|
this.novelChapterQueue = new NovelChapterQueue(this.fetchClient, this.logger);
|
|
1236
2667
|
this.novelInfoQueue = new NovelInfoQueue(this.fetchClient, this.novelChapterQueue, this.logger);
|
|
1237
2668
|
this.novelMediaQueue = new NovelMediaQueue(this.fetchClient, this.logger);
|
|
2669
|
+
this.novelExploreQueue = new NovelExploreQueue(this.fetchClient, this.logger);
|
|
1238
2670
|
this.searchSession = new SearchSession(this.fetchClient);
|
|
1239
2671
|
}
|
|
1240
2672
|
async ensureSession() {
|
|
@@ -1299,6 +2731,18 @@ var LinovelibClient = class {
|
|
|
1299
2731
|
}
|
|
1300
2732
|
return result?.content;
|
|
1301
2733
|
}
|
|
2734
|
+
getExploreSchema() {
|
|
2735
|
+
return LINOVELIB_EXPLORE_SCHEMA;
|
|
2736
|
+
}
|
|
2737
|
+
async getExploreHome(channel) {
|
|
2738
|
+
return await getExploreHome(channel, this.novelExploreQueue);
|
|
2739
|
+
}
|
|
2740
|
+
async getRankings(options) {
|
|
2741
|
+
return await getRankings(options, this.novelExploreQueue);
|
|
2742
|
+
}
|
|
2743
|
+
async getCatalog(options) {
|
|
2744
|
+
return await getCatalog(options, this.novelExploreQueue);
|
|
2745
|
+
}
|
|
1302
2746
|
};
|
|
1303
2747
|
// src/illustration.ts
|
|
1304
2748
|
function normalizeIllustrationUrl(rawSrc) {
|
|
@@ -1327,6 +2771,6 @@ function rewriteChapterIllustrations(html, mapUrl) {
|
|
|
1327
2771
|
});
|
|
1328
2772
|
return $.html();
|
|
1329
2773
|
}
|
|
1330
|
-
export { LinovelibClient, extractChapterIllustrationUrls, isUnresolvedChapterId, novelIdToCoverUrl, rewriteChapterIllustrations };
|
|
2774
|
+
export { LINOVELIB_CATALOG_ANIME_IDS, LINOVELIB_CATALOG_PROGRESS_IDS, LINOVELIB_CATALOG_REGION_IDS, LINOVELIB_CATALOG_SORT_IDS, LINOVELIB_CATALOG_TAG_IDS, LINOVELIB_CATALOG_UPDATED_IDS, LINOVELIB_CATALOG_WORDS_IDS, LINOVELIB_CHANNEL_IDS, LINOVELIB_DESKTOP_BASE, LINOVELIB_EXPLORE_SCHEMA, LINOVELIB_RANKING_IDS, LinovelibClient, buildCatalogUrl, buildRankingsUrl, extractChapterIllustrationUrls, extractNovelIdFromHref, isUnresolvedChapterId, isValidLinovelibChannel, isValidLinovelibRanking, normalizeCatalogOptions, novelIdToCoverUrl, parseCatalogHtml, parseHomeHtml, parseNovelStatusText, parseRankingsHtml, resolveDesktopCoverUrl, rewriteChapterIllustrations };
|
|
1331
2775
|
|
|
1332
2776
|
//# sourceMappingURL=index.mjs.map
|