@@ -6,6 +6,22 @@ const contextMenuId = "magnify-image";
66
77const CACHED = {
88 mouse : { x : 0 , y : 0 } ,
9+ configSize : null ,
10+ } ;
11+
12+ const MagnifySizeKey = "ufs_magnify_image_size" ;
13+ const getConfigSize = async ( ) => {
14+ if ( ! CACHED . configSize ) {
15+ const { Storage } = await import ( "./helpers/utils.js" ) ;
16+ const data = await Storage . get ( MagnifySizeKey ) ;
17+ CACHED . configSize = data ?. split ( "x" ) || [ 20 , 20 ] ;
18+ }
19+ return CACHED . configSize ;
20+ } ;
21+ const setConfigSize = async ( width , height ) => {
22+ const { Storage } = await import ( "./helpers/utils.js" ) ;
23+ CACHED . configSize = [ width , height ] ;
24+ return Storage . set ( MagnifySizeKey , width + "x" + height ) ;
925} ;
1026
1127export default {
@@ -56,6 +72,62 @@ export default {
5672 "2024-06-07" :
5773 "support video frame + right click anywhere + magnify on hover + search by images" ,
5874 } ,
75+ buttons : [
76+ {
77+ icon : '<i class="fa-solid fa-gear"></i>' ,
78+ name : {
79+ vi : "Cài đặt" ,
80+ en : "Setting" ,
81+ } ,
82+ onClick : async ( ) => {
83+ const { t } = await import ( "../popup/helpers/lang.js" ) ;
84+ const [ width , height ] = await getConfigSize ( ) ;
85+
86+ const result = await Swal . fire ( {
87+ title : t ( { vi : "Cài đặt phóng to" , en : "Magnify Setting" } ) ,
88+ html : `
89+ <p>${ t ( {
90+ vi : "Chỉ hiện nút phóng to cho hình ảnh có kích thước lớn hơn:" ,
91+ en : "Only show the magnify button when the image's size is larger than:" ,
92+ } ) } </p>
93+ <input
94+ style="display: inline-block;width: 40%"
95+ type="number"
96+ id="swal-input1"
97+ class="swal2-input"
98+ value="${ width } "
99+ placeholder="${ t ( { vi : "Rộng" , en : "Width" } ) } ">X
100+ <input
101+ style="display: inline-block;width: 40%"
102+ type="number"
103+ id="swal-input2"
104+ class="swal2-input"
105+ value="${ height } "
106+ placeholder="${ t ( { vi : "Cao" , en : "Height" } ) } ">
107+ ` ,
108+ preConfirm : ( ) => {
109+ return [
110+ document . getElementById ( "swal-input1" ) . value ,
111+ document . getElementById ( "swal-input2" ) . value ,
112+ ] ;
113+ } ,
114+ } ) ;
115+
116+ if ( result . isConfirmed ) {
117+ const [ width , height ] = result . value ;
118+ await setConfigSize ( width , height ) ;
119+ Swal . fire ( {
120+ icon : "success" ,
121+ title : t ( { vi : "Thành công" , en : "Success" } ) ,
122+ text : t ( {
123+ vi : "Cài đặt phóng to đã được cập nhật." ,
124+ en : "Magnify setting has been updated." ,
125+ } ) ,
126+ } ) ;
127+ }
128+ } ,
129+ } ,
130+ ] ,
59131
60132 popupScript : {
61133 onClick : ( ) => {
@@ -138,7 +210,11 @@ export default {
138210 addToDom ( ) ;
139211 UfsGlobal . DOM . onElementRemoved ( div , addToDom ) ;
140212
141- window . addEventListener ( "mouseover" , ( e ) => {
213+ window . addEventListener ( "mouseover" , async ( e ) => {
214+ const [ width , height ] = await getConfigSize ( ) ;
215+ if ( e . target . clientWidth < width || e . target . clientHeight < height )
216+ return ;
217+
142218 let srcs = getImgSrcsFromElement ( e . target ) ;
143219 if ( ! srcs ?. length ) {
144220 div . classList . toggle ( "hide" , e . target !== div ) ;
0 commit comments