@@ -4,6 +4,8 @@ import { getAdPageByContent, getAdPageByFileName } from 'userscript/detectAd';
44
55import type { GalleryContext } from './helper' ;
66
7+ import { extractSpriteImage } from '../../helper/spriteImage' ;
8+
79/** 识别广告 */
810export const detectAd = ( {
911 store : { comicMap } ,
@@ -20,43 +22,43 @@ export const detectAd = ({
2022 setState ( 'comicMap' , '' , 'adList' , new ReactiveSet ( ) ) ;
2123
2224 /** 缩略图列表 */
23- const thumbnailList : ( string | HTMLImageElement ) [ ] = [ ] ;
24- for ( const e of querySelectorAll < HTMLAnchorElement > ( '#gdt > a' ) ) {
25- const index = Number ( / .+ - ( \d + ) / . exec ( e . href ) ?. [ 1 ] ) - 1 ;
26- if ( Number . isNaN ( index ) ) continue ;
27- pageList [ index ] = e . href ;
25+ const thumbnailList : ( ImageBitmap | HTMLImageElement ) [ ] = [ ] ;
26+ ( async ( ) => {
27+ for ( const e of querySelectorAll < HTMLAnchorElement > ( '#gdt > a' ) ) {
28+ const index = Number ( / .+ - ( \d + ) / . exec ( e . href ) ?. [ 1 ] ) - 1 ;
29+ if ( Number . isNaN ( index ) ) continue ;
30+ pageList [ index ] = e . href ;
2831
29- const thumbnail = e . querySelector < HTMLElement > ( '[title]' ) ! ;
30- [ , fileNameList [ index ] ] = thumbnail . title . split ( / : | : / ) ;
31- thumbnailList [ index ] =
32- thumbnail . tagName === 'IMG'
33- ? ( thumbnail as HTMLImageElement )
34- : / u r l \( " ( . + ) " \) / . exec ( thumbnail . style . backgroundImage ) ! [ 1 ] ;
35- }
32+ const thumbnail = e . querySelector < HTMLElement > ( '[title]' ) ! ;
33+ [ , fileNameList [ index ] ] = thumbnail . title . split ( / : | : / ) ;
34+ if ( thumbnail . tagName === 'IMG' )
35+ thumbnailList [ index ] = thumbnail as HTMLImageElement ;
36+ if ( thumbnail . style . background . includes ( 'url(' ) )
37+ thumbnailList [ index ] = await extractSpriteImage ( thumbnail . style ) ;
38+ }
3639
37- ( async ( ) => {
3840 // 先根据文件名判断一次
3941 await getAdPageByFileName ( fileNameList , comicMap [ '' ] . adList ! ) ;
4042 // 不行的话再用缩略图识别
4143 if ( comicMap [ '' ] . adList ! . size === 0 )
4244 await getAdPageByContent ( thumbnailList , comicMap [ '' ] . adList ! ) ;
45+ } ) ( ) ;
4346
44- // 模糊广告页的缩略图
45- useStyle (
46- createRootMemo ( ( ) => {
47- if ( ! comicMap [ '' ] ?. adList ?. size ) return '' ;
48- return [ ...comicMap [ '' ] . adList ]
49- . map (
50- ( i ) => `a[href="${ pageList [ i ] } "] [title]:not(:hover) {
47+ // 模糊广告页的缩略图
48+ useStyle (
49+ createRootMemo ( ( ) => {
50+ if ( ! comicMap [ '' ] ?. adList ?. size ) return '' ;
51+ return [ ...comicMap [ '' ] . adList ]
52+ . map (
53+ ( i ) => `a[href="${ pageList [ i ] } "] [title]:not(:hover) {
5154 filter: blur(8px);
5255 clip-path: border-box;
5356 backdrop-filter: blur(8px);
5457 }` ,
55- )
56- . join ( '\n' ) ;
57- } ) ,
58- ) ;
59- } ) ( ) ;
58+ )
59+ . join ( '\n' ) ;
60+ } ) ,
61+ ) ;
6062
6163 // 返回在图片加载时检查图片的函数
6264 return {
0 commit comments