11import { type Accessor , For , createSignal , Show } from 'solid-js' ;
22import { render } from 'solid-js/web' ;
33import { request , toast } from 'main' ;
4- import { t , domParse , querySelector , querySelectorAll } from 'helper' ;
4+ import { t , domParse , querySelector , querySelectorAll , useStyle } from 'helper' ;
55
6- import type { EhContext } from './context ' ;
6+ import type { EhContext } from './helper ' ;
77
8- let hasStyle = false ;
98const addQuickFavorite = (
109 favoriteButton : HTMLElement ,
1110 root : HTMLElement ,
1211 apiUrl : string ,
13- position : [ number , number ] ,
12+ height : number ,
13+ top = 0 ,
1414) => {
15- if ( ! hasStyle ) {
16- hasStyle = true ;
17- GM_addStyle ( `
15+ useStyle ( `
1816 .comidread-favorites {
1917 position: absolute;
2018 z-index: 75;
@@ -31,42 +29,40 @@ const addQuickFavorite = (
3129 border-radius: 0;
3230 }
3331
34- .comidread-favorites-item {
35- cursor: pointer;
32+ .comidread-favorites-item {
33+ cursor: pointer;
3634
37- display: flex;
38- align-items: center;
35+ display: flex;
36+ align-items: center;
3937
40- width: 100%;
41- margin: 1em 0;
38+ width: 100%;
39+ margin: 1em 0;
4240
43- text-align: left;
44- overflow-wrap: anywhere;
45- }
41+ text-align: left;
42+ overflow-wrap: anywhere;
43+ }
4644
47- .comidread-favorites-item > input {
48- pointer-events: none;
49- margin: 0 0.5em 0 0;
50- }
45+ .comidread-favorites-item > input {
46+ pointer-events: none;
47+ margin: 0 0.5em 0 0;
48+ }
5149
52- .comidread-favorites-item > div {
53- flex-shrink: 0;
50+ .comidread-favorites-item > div {
51+ flex-shrink: 0;
5452
55- width: 15px;
56- height: 15px;
57- margin: 0 0.5em 0 0;
53+ width: 15px;
54+ height: 15px;
55+ margin: 0 0.5em 0 0;
5856
59- background-image: url("https://ehgt.org/g/fav.png");
60- background-repeat: no-repeat;
61- }
57+ background-image: url("https://ehgt.org/g/fav.png");
58+ background-repeat: no-repeat;
59+ }
6260
6361 .gl1t > .comidread-favorites {
6462 padding: 1em 1.5em;
6563 }
66- ` ) ;
67- }
64+ ` ) ;
6865 root . style . position = 'relative' ;
69- root . style . height = '100%' ;
7066
7167 const [ show , setShow ] = createSignal ( false ) ;
7268
@@ -155,8 +151,8 @@ const addQuickFavorite = (
155151 class = "comidread-favorites"
156152 style = { {
157153 background,
158- height : `${ position [ 1 ] - position [ 0 ] } px` ,
159- top : `${ position [ 0 ] } px` ,
154+ height : `${ height } px` ,
155+ top : `${ top } px` ,
160156 } }
161157 >
162158 < For
@@ -195,10 +191,8 @@ export const quickFavorite = (context: EhContext) => {
195191 case 'gallery' : {
196192 const button = querySelector ( '#gdf' ) ! ;
197193 const root = querySelector ( '#gd3' ) ! ;
198- addQuickFavorite ( button , root , `${ unsafeWindow . popbase } addfav` , [
199- 0 ,
200- ( button . firstElementChild as HTMLElement ) . offsetTop ,
201- ] ) ;
194+ const height = ( button . firstElementChild as HTMLElement ) . offsetTop ;
195+ addQuickFavorite ( button , root , `${ unsafeWindow . popbase } addfav` , height ) ;
202196 break ;
203197 }
204198
@@ -212,7 +206,7 @@ export const quickFavorite = (context: EhContext) => {
212206 item . lastElementChild ! . getBoundingClientRect ( ) . top -
213207 item . getBoundingClientRect ( ) . top ;
214208 const apiUrl = / h t t p .+ ?(? = ' ) / . exec ( button . getAttribute ( 'onclick' ) ! ) ! [ 0 ] ;
215- addQuickFavorite ( button , item , apiUrl , [ top , bottom ] ) ;
209+ addQuickFavorite ( button , item , apiUrl , bottom - top , top ) ;
216210 }
217211 break ;
218212 }
@@ -221,9 +215,9 @@ export const quickFavorite = (context: EhContext) => {
221215 for ( const item of querySelectorAll ( '.gl1e' ) ) {
222216 const button =
223217 item . nextElementSibling ! . querySelector < HTMLElement > ( '[id^=posted_]' ) ! ;
224- const bottom = Number . parseInt ( getComputedStyle ( item ) . height , 10 ) ;
218+ const height = Number . parseInt ( getComputedStyle ( item ) . height , 10 ) ;
225219 const apiUrl = / h t t p .+ ?(? = ' ) / . exec ( button . getAttribute ( 'onclick' ) ! ) ! [ 0 ] ;
226- addQuickFavorite ( button , item , apiUrl , [ 0 , bottom ] ) ;
220+ addQuickFavorite ( button , item , apiUrl , height ) ;
227221 }
228222 break ;
229223 }
0 commit comments