Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions plugins/vietnamese/SangTacViet/content-normalization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/* eslint-disable no-useless-escape */

import { decodeHtmlEntities, encodeHtmlEntities } from '@libs/utils';
Comment thread
aiko-chan-ai marked this conversation as resolved.
import { decodeGlyphs } from './glyph-decode';

// ── Content normalization ─────────────────
function looksLikeInterlinear(text: string): boolean {
return /<i\b[^>]*\b(?:t|v|p)\s*=\s*['"][^'"]*['"][^>]*>/i.test(text);
}

function normalizeInterlinear(raw: string): string {
let t = raw.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
t = t.replace(/<br\s*\/?>\s*/gi, '\n').replace(/<\/br\s*>/gi, '\n');
t = t.replace(
/<\/i>\s*\n+\s*(?=[,.;:!?%\)\]\}\u3002\uff0c\u3001\uff01\uff1f\uff1b\uff1a\u201d\u2019\u300d\u300f\u3011\u300b])/gi,
'</i>',
);
const marker = '__STV_GAP__';
t = t.replace(/<\/i>\s*<i\b/gi, '</i>' + marker + '<i');
t = t.replace(/<i\b[^>]*>([\s\S]*?)<\/i>/gi, '$1');
t = t.replace(
/<\/?(p|div|article|section|li|tr|h[1-6]|blockquote|ul|ol)[^>]*>/gi,
'\n',
);
t = t.replace(/<[^>]+>/g, '').replace(/[<>]/g, '');
t = decodeHtmlEntities(t);
t = t.replace(new RegExp(marker, 'g'), ' ');
t = t.replace(/[\t\f\v ]+/g, ' ');
t = t.replace(
/ +([,.;:!?%\)\]\}\u3002\uff0c\u3001\uff01\uff1f\uff1b\uff1a\u201d\u2019\u300d\u300f\u3011\u300b])/g,
'$1',
);
t = t.replace(
/\n+([,.;:!?%\)\]\}\u3002\uff0c\u3001\uff01\uff1f\uff1b\uff1a\u201d\u2019\u300d\u300f\u3011\u300b])/g,
'$1',
);
t = t
.replace(/[ ]*\n[ ]*/g, '\n')
.replace(/\n{3,}/g, '\n\n')
.trim();
return t ? t.replace(/\n/g, '<br>') : '';
}

export function normalizeChapterHtml(host: string, raw: string): string {
let text = raw || '';
if (!text) return '';
const h = host.toLowerCase();

if (h === 'fanqie') {
text = text.replace(/<header[^>]*>[\s\S]*?<\/header>/gi, '');
text = text.replace(/<footer[^>]*>[\s\S]*?<\/footer>/gi, '');
text = text.replace(/<\/?article>/gi, '');
text = text.replace(/\sidx="\d+"/g, '');
if (looksLikeInterlinear(text)) return normalizeInterlinear(text);
return text;
}

if (h === 'sangtac' || h === 'dich') {
text = decodeGlyphs(text);
if (looksLikeInterlinear(text)) return normalizeInterlinear(text);
if (!/<\w+[^>]*>/.test(text)) {
text = text
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
text = text
.replace(/\r\n/g, '\n')
.replace(/\r/g, '\n')
.replace(/\n/g, '<br>');
}
return text;
}

if (!/<\w+[^>]*>/.test(text)) {
text = text
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
text = text
.replace(/\r\n/g, '\n')
.replace(/\r/g, '\n')
.replace(/\n/g, '<br>');
return text;
}
if (looksLikeInterlinear(text)) return normalizeInterlinear(text);
return text;
}

export function wrapWithParagraphs(rawText: string): string {
if (!rawText) return '';
const cleanText = rawText.replace(/<br\s*\/?>/gi, '\n');
const paragraphs = cleanText.split('\n');
const htmlResult = paragraphs
.map(line => line.trim())
.filter(line => line.length > 0)
.map(line => `<p>${encodeHtmlEntities(line)}</p>`)
.join('\n');
return htmlResult;
}
168 changes: 168 additions & 0 deletions plugins/vietnamese/SangTacViet/external-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/* eslint-disable no-useless-escape */

// ── External-URL
const HOST_PATTERNS: Record<string, string[]> = {
uukanshu: [
'uukanshu\\.(?:com|net)/b/(\\d+)/(\\d+)?(.html)?',
'sj\\.uukanshu\\.(?:com|net)//?book(?:_amp)?\\.aspx\\?id=(\\d+)',
'sj\\.uukanshu\\.(?:com|net)//?read\\.aspx?tid=(\\d+)&sid=(\\d+)',
'zhaoshuyuan\\.(?:com|net)/b/(\\d+)/(\\d+)?(.html)?',
'zhaoshuyuan\\.(?:com|net)//?book(?:_amp)?\\.aspx\\?id=(\\d+)',
'zhaoshuyuan\\.(?:com|net)//?read\\.aspx?tid=(\\d+)&sid=(\\d+)',
],
'69shu': [
'69shuba\\.com/(?:txt|book/)?(\\d+)/?(\\d+)?',
'69shuba\\.cx/(?:txt|book/)?(\\d+)/?(\\d+)?',
'69xinshu\\.com/(?:txt|book/)?(\\d+)/?(\\d+)?',
'69shu\\.pro/(?:txt|book/)?(\\d+)/?(\\d+)?',
'69shu\\.[a-z]{3,4}/(?:txt|book/)?(\\d+)/?(\\d+)?',
'69shuba\\.[a-z]{3,4}/(?:txt|book/)?(\\d+)/?(\\d+)?',
],
'69shuorg': ['69shu\\.org/book[_/](\\d+)/(\\d+)?'],
xiaoqiangwx: ['xiaoqiangwx\\.org/(?:\\d+|book)/(\\d+)/?(\\d+)?(.html)?'],
cuiweijux: ['cuiweijux\\.com/files/article/html/\\d+/(\\d+)/(\\d+)?(.html)?'],
biquge: [
'biquge\\.com\\.cn/book/(\\d+)/(\\d+)?(.html)?',
'sobiquge\\.com/book/(\\d+)/',
'81zw\\.org/books/(\\d+)/',
],
trxs: ['trxs\\.cc/tongren/(\\d+)/?(\\d+)?(.html)?'],
ikshu8: ['ikshu8\\.com/book/(\\d+)/?(\\d+)?(.html)?'],
shulinw: [
'shulinw\\.com/(?:shu/|yuedu/|book/|\\d+/|modules/article/articleinfo\\.php\\?id=)(\\d+)(?:/)?(\\d*)(.html)?',
],
wuxia1: [
'wuxia1\\.com/(?:shu/|yuedu/|book/|\\d+/|modules/article/articleinfo\\.php\\?id=)(\\d+)(?:/)?(\\d*)(.html)?',
],
shu05: ['shu05\\.com/\\d+[/_](\\d+)/(\\d*)(.html)?'],
kuhu168: ['kuhu168\\.com/\\d+[/_](\\d+)/(\\d*)(.html)?'],
'2kxs': ['2kxs\\.org/\\d+[/_](\\d+)/(\\d*)(.html)?'],
yikanxiaoshuo: ['yikanxiaoshuo\\.com/\\d+[/_](\\d+)/(\\d*)(.html)?'],
'8zwdu': ['8zwdu\\.com/\\d+[/_](\\d+)/(\\d*)(.html)?'],
kanmaoxian: ['kanmaoxian\\.com/(?:book|\\d+)/(\\d+)/?(\\d*)(.html)?'],
kayegenet: ['kayege\\.net/(?:book|\\d+)[/_](\\d+)/?(\\d*)(.html)?'],
'4gxsw': ['4gxsw\\.com/(?:book|html/\\d+)/(\\d+)/?(\\d*)(.html)?'],
qinqinxsw: ['qinqinxsw\\.com/(?:book|\\d+)[/_](\\d+)/?(\\d*)(.html)?'],
read8: ['read8\\.net/(?:dushu)/(\\d+)/(\\d*)(.html)?'],
ciweimao: ['ciweimao\\.com/book/(\\d+)'],
wkkshu: ['wkkshu\\.com/(?:xs/\\d+/|\\d+_)(\\d+)/(\\d*)(.html)?'],
'168kanshu': ['168kanshu\\.com/(?:xs/\\d+/|\\d+_)(\\d+)/(\\d*)(.html)?'],
wanbentxt: ['wanbentxt\\.com/(\\d+)/([\\d_]*)(.html)?'],
'38kanshu': ['mijiashe\\.com/(\\d+)/([\\d_]*)(.html)?'],
duanqingsi: ['duanqingsi\\.com/(\\d+)/([\\d_]*)(.html)?'],
faloo: [
'\\.faloo\\.com/[pfboklithtm]+/(\\d+)(?:\\.html|/(\\d+)\\.html)?',
'\\.faloo\\.com/(\\d+)\\.html',
'\\.faloo\\.com/(\\d+)_(\\d+)\\.html',
],
qiuxiaoshuo: ['qiuxiaoshuo\\.com/(?:book|read)[/-](\\d+)[/-]?(\\d*)'],
dibaqu123: ['dibaqu123\\.com/\\d+/(\\d+)/?(\\d*)(.html)?'],
jiacuan: ['jiacuan\\.com/\\d+/(\\d+)/(\\d*)(.html)?'],
shubaow: ['shubaow\\.net/\\d+[_/](\\d+)/(\\d*)(.html)?'],
biqugeinfo: ['biquge\\.info/\\d+_(\\d+)/(\\d*)(.html)?'],
shumilou: ['shumilou\\.net/\\d+/(\\d+)/(\\d*)(.html)?'],
xbiquge: ['xbiquge\\.cc/book/(\\d+)/(\\d*)(.html)?'],
paoshu8: ['paoshu8\\.com/\\d+_(\\d+)/(\\d*)(.html)?'],
duokan8: ['duokan8\\.com/\\d+_(\\d+)/(\\d*)(.html)?'],
biqugecom: ['biquge\\.com/\\d+_(\\d+)/(\\d*)(.html)?'],
hetushu: ['hetushu\\.com/book/(\\d+)/(\\d*)(.html)?'],
nofff: ['nofff\\.com/(\\d+)/(\\d*)/?'],
uuxs: ['uuxs\\.tw/ls/\\d+_(\\d+)/(\\d*)(.html)?'],
ranwenla: ['ranwen\\.la/files/article/\\d+/(\\d+)/(\\d*)(.html)?'],
'66wx': ['66wx\\.com/(\\d+)_\\d+/read(\\d*)(.html)?'],
biqugexs: ['biqugexs\\.com/\\d+_(\\d+)/(\\d*)(.html)?'],
'230book': ['230book\\.[comnet]{3}/book/(\\d+)/(\\d*)(.html)?'],
biqubu: ['biqubu\\.com/book_(\\d+)/(\\d*)(.html)?'],
'521danmei': [
'521danmei\\.org/read/(\\d+)/(\\d*)/?',
'521danmei\\.org/book/(\\d+)\\.html',
],
bxwxorg: [
'bxwxorg\\.com/read/(\\d+)/(\\d*)(.html)?',
'bxwxorg\\.com/book/(\\d+)\\.html',
],
qidian: ['qidian\\.com/(?:book|info)/(\\d+)'],
zwdu: ['zwdu\\.com/book/(\\d+)/(\\d*)(.html)?'],
zongheng: [
'book\\.zongheng\\.com/chapter/(\\d+)/(\\d*)(.html)?',
'book\\.zongheng\\.com/book/(\\d+)(?:\\.html)?',
],
biqugese: [
'biquge\\.se/(\\d+)/(\\d*)(.html)?',
'biqugse\\.com/(\\d+)/(\\d*)(.html)?',
],
qiushubang: ['qiushubang\\.com/(\\d+)/(\\d*)(.html)?'],
xinshuhaige: ['xinshuhaige\\.com/(\\d+)/(\\d*)(.html)?'],
oldtimescc: ['oldtimescc\\.cc/go/(\\d+)/(\\d*)(.html)?'],
wuwuxs: ['wuwuxs\\.com/\\d+_(\\d+)/(\\d*)(.html)?'],
hs313: ['hs313\\.net/book/(\\d+)/(\\d*)(.html)?'],
shuchong: ['shuchong\\.info/chapter/(\\d+)/(\\d*)(.html)?'],
shucw: ['shucw\\.com/html/\\d+/(\\d+)/(\\d*)(.html)?'],
shumizu: ['shumizu\\.com/\\d+/(\\d+)/(\\d*)(.html)?'],
tadu: ['tadu\\.com/book/(\\d+)/?(\\d*)/?'],
ptwxz: [
'ptwxz\\.com/bookinfo/\\d+/(\\d+)\\.html',
'ptwxz\\.com/html/\\d+/(\\d+)/(\\d+)\\.html',
'ptwxz\\.com/html/\\d+/(\\d+)/',
],
x81zw: ['x81zw\\.com/book/\\d+/(\\d+)/(\\d*)(.html)?'],
linovel: ['linovel\\.net/book/(\\d+)\\.html'],
wenku8: ['wenku8\\.net/novel/\\d+/(\\d+)/(\\d*)\\.htm'],
youyoukanshu: [
'youyoukanshu\\.com/book/(\\d+)\\.html',
'youyoukanshu\\.com/book/(\\d+)/(\\d*)(.html)?',
],
biqubao: ['biqubao\\.com/book/(\\d+)/(\\d*)(.html)?'],
biqugele: ['biqugele\\.com/txt/(\\d+)/(\\d*)(.html)?'],
biqugebz: ['biquge\\.bz/(\\d+)/(\\d*)(.html)?'],
biquge5200: ['biquge5200\\.cc/\\d+_(\\d+)/(\\d*)(.html)?'],
sfacg: [
'sfacg\\.com/(?:Novel|b|i)/(\\d+)/?',
'sfacg\\.com/Novel/(\\d+)/MainIndex/',
],
shubao45: ['shubao45\\.com/\\d+_(\\d+)/(\\d*)(.html)?'],
kujiang: ['kujiang\\.com/book/(\\d+)'],
yushubo: [
'yushubo\\.com/book_(\\d+)',
'yushubo\\.net/book_(\\d+)',
'yushugu\\.com/book_(\\d+)',
'yushugu\\.com/list_other_(\\d+)',
'yushugu\\.com/read_(\\d+)_(\\d+)\\.html',
],
xklxsw: ['xklxsw\\.com/book/(\\d+)/'],
fanqie: ['fanqienovel\\.com/page/(\\d+)'],
xsbiquge: ['xsbiquge\\.net/\\d+_(\\d+)/(\\d*)(.html)?'],
jjwxc: [
'jjwxc\\.net//?onebook\\.php\\?novelid=(\\d+)',
'jjwxc\\.net//?book2/(\\d+)/?',
],
qimao: ['qimao\\.com/shuku/(\\d+)/'],
ddxs: ['ddxs\\.com/([a-z0-9A-Z\\-_]+)/(\\d+)?'],
quanben5: ['quanben5\\.com/n/([a-z0-9A-Z\\-_]+)/'],
idejian: ['idejian\\.com/book/([0-9]+)/'],
};

// Hosts whose first capture is alphanumeric and must be resolved to a numeric
// bookid via /index.php?sajax=tryaddabtrecord (mirrors `isAbtHost()`).
export const ABT_HOSTS = new Set(['ddxs', 'quanben5', 'colamanga']);

export function looksLikeExternalUrl(s: string): boolean {
const t = s.toLowerCase();
return t.startsWith('http://') || t.startsWith('https://');
}

export function detectHostFromUrl(
input: string,
): { host: string; bookid: string; chapterid?: string } | null {
for (const host in HOST_PATTERNS) {
for (const pat of HOST_PATTERNS[host]) {
const m = new RegExp(pat, 'i').exec(input);
if (!m) continue;
if (m[2] !== undefined && m[2] !== m[1] && /^[\d_\-]+$/.test(m[2])) {
if (m[1]) return { host, bookid: m[1], chapterid: m[2] };
}
if (m[1]) return { host, bookid: m[1] };
}
}
return null;
}
127 changes: 127 additions & 0 deletions plugins/vietnamese/SangTacViet/filters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { type Filters, FilterTypes } from '@libs/filterInputs';

export const filters = {
sort: {
type: FilterTypes.Picker,
label: 'Sắp xếp',
value: 'view',
options: [
{ label: 'Không sắp xếp', value: '' },
{ label: 'Mới nhập kho', value: 'new' },
{ label: 'Mới cập nhật', value: 'update' },
{ label: 'Lượt đọc tổng', value: 'view' },
{ label: 'Lượt đọc tuần', value: 'viewweek' },
{ label: 'Lượt đọc ngày', value: 'viewday' },
{ label: 'Lượt thích', value: 'like' },
{ label: 'Lượt theo dõi', value: 'following' },
{ label: 'Lượt đánh dấu', value: 'bookmarked' },
{ label: 'Đề cử', value: 'auto' },
],
},
minc: {
type: FilterTypes.Picker,
label: 'Số chương tối thiểu',
value: '0',
options: [
{ label: 'Tất cả', value: '0' },
{ label: '> 50', value: '50' },
{ label: '> 100', value: '100' },
{ label: '> 200', value: '200' },
{ label: '> 500', value: '500' },
{ label: '> 1000', value: '1000' },
{ label: '> 1500', value: '1500' },
{ label: '> 2000', value: '2000' },
],
},
category: {
type: FilterTypes.Picker,
label: 'Thể loại chính',
value: '',
options: [
{ label: 'Tất cả', value: '' },
{ label: 'Huyền huyễn', value: 'hh' },
{ label: 'Đô thị', value: 'dt' },
{ label: 'Ngôn tình', value: 'nt' },
{ label: 'Võng du', value: 'vd' },
{ label: 'Khoa học viễn tưởng', value: 'kh' },
{ label: 'Lịch sử', value: 'ls' },
{ label: 'Đồng nhân', value: 'dn' },
{ label: 'Dị năng', value: 'dna' },
{ label: 'Linh dị', value: 'ld' },
{ label: 'Light Novel', value: 'ln' },
],
},
type: {
type: FilterTypes.Picker,
label: 'Loại truyện',
value: '',
options: [
{ label: 'Tất cả', value: '' },
{ label: 'Truyện sáng tác', value: 'sangtac' },
{ label: 'Truyện dịch', value: 'dich' },
{ label: 'Truyện tranh', value: 'comic' },
{ label: 'Txt dịch tự động', value: 'txt' },
{ label: 'Truyện scan ảnh', value: 'scan' },
],
},
step: {
type: FilterTypes.Picker,
label: 'Trạng thái đăng',
value: '',
options: [
{ label: 'Tất cả', value: '' },
{ label: 'Hoàn thành', value: '3' },
{ label: 'Còn tiếp', value: '1' },
{ label: 'Tạm ngưng', value: '2' },
{ label: 'Không tạm ngưng', value: '5' },
],
},
host: {
type: FilterTypes.Picker,
label: 'Nguồn truyện',
value: '',
options: [
{ label: 'Tất cả', value: '' },
{ label: '[Vip] fanqie (Cà Chua)', value: 'fanqie' },
{ label: '[Vip] qidian (Khởi Điểm)', value: 'qidian' },
{ label: '[Vip] ciweimao', value: 'ciweimao' },
{ label: '[Vip] faloo (Phi Lư)', value: 'faloo' },
{ label: '[Vip] jjwxc (Tấn Giang)', value: 'jjwxc' },
{ label: '[Vip] sfacg', value: 'sfacg' },
{ label: '[Vip] zongheng (Tung Hoành)', value: 'zongheng' },
{ label: '[Free] 69shu', value: '69shu' },
{ label: '[Free] tadu', value: 'tadu' },
{ label: '[Free] qimao (7 Mèo)', value: 'qimao' },
{ label: '[Free] idejian', value: 'idejian' },
{ label: '[LN] linovel', value: 'linovel' },
{ label: '[LN] wenku8', value: 'wenku8' },
],
},
tag: {
type: FilterTypes.CheckboxGroup,
label: 'Nhãn',
value: [],
options: [
{ label: 'Đô Thị', value: 'dothi' },
{ label: 'Xuyên Qua', value: 'xuyenqua' },
{ label: 'Hệ Thống', value: 'hethong' },
{ label: 'Huyền Huyễn', value: 'huyenhuyen' },
{ label: 'Ngôn Tình', value: 'ngontinh' },
{ label: 'Đồng Nhân', value: 'dongnhan' },
{ label: 'Trùng Sinh', value: 'trungsinh' },
{ label: 'Lịch Sử', value: 'lichsu' },
{ label: 'Khoa Huyễn', value: 'khoahuyen' },
{ label: 'Tiên Hiệp', value: 'tienhiep' },
{ label: 'Võ Hiệp', value: 'vohiep' },
{ label: 'Sảng Văn', value: 'sangvan' },
{ label: 'Light Novel', value: 'lightnovel' },
{ label: 'Linh Dị', value: 'linhdi' },
{ label: 'Kỳ Huyễn', value: 'kyhuyen' },
{ label: 'Tận Thế', value: 'tanthe' },
{ label: 'Ngọt Sủng', value: 'ngotsung' },
{ label: 'Sân Trường', value: 'santruong' },
{ label: 'Nhiệt Huyết', value: 'nhiethuyet' },
{ label: 'Nhanh Xuyên', value: 'nhanhxuyen' },
],
},
} satisfies Filters;
Loading
Loading