@@ -5,15 +5,15 @@ import { setupEasterEggs } from "./eggs.js";
55import { scriptPath , pluginPath , scriptioVersion } from "../loaders/unified.js" ;
66
77/** Scriptio plugin uri */
8- const pluginUri = window . LiteLoader ? `local:/// ${ pluginPath } ` : qwqnt . framework . protocol . pathToStorageUrl ( pluginPath ) ;
8+ const pluginUri = qwqnt . framework . protocol . pathToStorageUrl ( pluginPath ) ;
99/** Attribute of `<setting-item>` that stores the script path */
1010const configDataAttr = "data-scriptio-config" ;
1111/** Attribute of `<setting-switch>` that stores the script path */
1212const switchDataAttr = "data-scriptio-switch" ;
1313/** Attribute of `<setting-item>` that indicates the script is deleted */
1414const deletedDataAttr = "data-deleted" ;
1515/** Function to manually trigger the search (re-search) */
16- let research = ( ) => { } ; // Placeholder for the search function
16+ let research = ( ) => { } ; // Placeholder for the search function
1717
1818/** Function to add a button to the right side of the setting item.
1919 * @param {Element } right The right side element.
@@ -43,19 +43,37 @@ function addItem(path, container) {
4343 itemDesc . setAttribute ( "data-type" , "secondary" ) ;
4444 const right = item . appendChild ( document . createElement ( "div" ) ) ;
4545 right . classList . add ( "scriptio-menu" ) ;
46- const homepage = addScriptioMore ( right , { icon : "🔗" , title : "打开脚本主页" , className : "scriptio-homepage" } ) ;
46+ const homepage = addScriptioMore ( right , {
47+ icon : "🔗" ,
48+ title : "打开脚本主页" ,
49+ className : "scriptio-homepage" ,
50+ } ) ;
4751 homepage . addEventListener ( "click" , ( ) => {
48- if ( ! item . hasAttribute ( deletedDataAttr ) && ! homepage . hasAttribute ( "disabled" ) ) {
49- scriptio_internal . open ( "link" , homepage . getAttribute ( "data-homepage-url" ) ) ;
52+ if (
53+ ! item . hasAttribute ( deletedDataAttr ) &&
54+ ! homepage . hasAttribute ( "disabled" )
55+ ) {
56+ scriptio_internal . open (
57+ "link" ,
58+ homepage . getAttribute ( "data-homepage-url" ) ,
59+ ) ;
5060 }
5161 } ) ;
52- const remove = addScriptioMore ( right , { icon : "🗑️" , title : "删除此脚本" , className : "scriptio-remove" } ) ;
62+ const remove = addScriptioMore ( right , {
63+ icon : "🗑️" ,
64+ title : "删除此脚本" ,
65+ className : "scriptio-remove" ,
66+ } ) ;
5367 remove . addEventListener ( "click" , ( ) => {
5468 if ( ! item . hasAttribute ( deletedDataAttr ) ) {
5569 scriptio_internal . removeScript ( path ) ;
5670 }
5771 } ) ;
58- const showInFolder = addScriptioMore ( right , { icon : "📂" , title : "在文件夹中显示" , className : "scriptio-folder" } ) ;
72+ const showInFolder = addScriptioMore ( right , {
73+ icon : "📂" ,
74+ title : "在文件夹中显示" ,
75+ className : "scriptio-folder" ,
76+ } ) ;
5977 showInFolder . addEventListener ( "click" , ( ) => {
6078 if ( ! item . hasAttribute ( deletedDataAttr ) ) {
6179 scriptio_internal . open ( "show" , scriptPath + path ) ;
@@ -67,7 +85,10 @@ function addItem(path, container) {
6785 switch_ . addEventListener ( "click" , ( ) => {
6886 if ( ! item . hasAttribute ( deletedDataAttr ) ) {
6987 switch_ . parentNode . classList . toggle ( "is-loading" , true ) ;
70- scriptio_internal . configChange ( path , switch_ . toggleAttribute ( "is-active" ) ) ; // Update the UI immediately, so it would be more smooth
88+ scriptio_internal . configChange (
89+ path ,
90+ switch_ . toggleAttribute ( "is-active" ) ,
91+ ) ; // Update the UI immediately, so it would be more smooth
7192 }
7293 } ) ;
7394 return item ;
@@ -102,17 +123,22 @@ async function initScriptioSettings(view) {
102123 console . log ( "[Scriptio] Ignored" , file . name ) ;
103124 continue ;
104125 }
105- promises . push ( new Promise ( ( resolve , reject ) => {
106- cnt ++ ;
107- console . log ( "[Scriptio] Importing" , file . name ) ;
108- let reader = new FileReader ( ) ;
109- reader . onload = ( ) => {
110- scriptio_internal . importScript ( file . name , reader . result ) ;
111- console . log ( "[Scriptio] Imported" , file . name ) ;
112- resolve ( ) ;
113- } ;
114- reader . readAsText ( file ) ;
115- } ) ) ;
126+ promises . push (
127+ new Promise ( ( resolve , reject ) => {
128+ cnt ++ ;
129+ console . log ( "[Scriptio] Importing" , file . name ) ;
130+ let reader = new FileReader ( ) ;
131+ reader . onload = ( ) => {
132+ scriptio_internal . importScript (
133+ file . name ,
134+ reader . result ,
135+ ) ;
136+ console . log ( "[Scriptio] Imported" , file . name ) ;
137+ resolve ( ) ;
138+ } ;
139+ reader . readAsText ( file ) ;
140+ } ) ,
141+ ) ;
116142 }
117143 await Promise . all ( promises ) ;
118144 this . parentNode . classList . toggle ( "is-loading" , false ) ;
@@ -128,36 +154,42 @@ async function initScriptioSettings(view) {
128154 // Dev mode
129155 const dev = $ ( "#scriptio-dev" ) ;
130156 dev . addEventListener ( "click" , devMode ) ;
131- scriptio_internal . queryDevMode ( ) . then ( enabled => {
157+ scriptio_internal . queryDevMode ( ) . then ( ( enabled ) => {
132158 log ( "queryDevMode" , enabled ) ;
133159 dev . toggleAttribute ( "is-active" , enabled ) ;
134160 } ) ;
135161 // Debug mode
136162 showDebugHint ( view ) ;
137163 // Buttons
138- $ ( "#scriptio-reload" ) . addEventListener ( "dblclick" , scriptio_internal . reload ) ;
164+ $ ( "#scriptio-reload" ) . addEventListener (
165+ "dblclick" ,
166+ scriptio_internal . reload ,
167+ ) ;
139168 $ ( "#scriptio-open-folder" ) . addEventListener ( "click" , ( ) => {
140169 openURI ( "path" , scriptPath ) ;
141170 } ) ;
142171 $ ( "#scriptio-import" ) . addEventListener ( "change" , importScript ) ;
143172 // About - Version
144173 $ ( "#scriptio-version" ) . textContent = scriptioVersion ;
145174 // About - Backgroud image
146- [ "version" , "author" , "issues" , "submit" ] . forEach ( id => {
147- $ ( `#scriptio-about-${ id } ` ) . style . backgroundImage = `url("${ pluginUri } /icons/${ id } .svg")` ;
175+ [ "version" , "author" , "issues" , "submit" ] . forEach ( ( id ) => {
176+ $ ( `#scriptio-about-${ id } ` ) . style . backgroundImage =
177+ `url("${ pluginUri } /icons/${ id } .svg")` ;
148178 } ) ;
149179 // Logo
150180 const logo = $ ( ".logo" ) ;
151181 logo . src = pluginUri + "/icons/icon.svg" ;
152182 // Links
153- view . querySelectorAll ( ".scriptio-link" ) . forEach ( link => {
183+ view . querySelectorAll ( ".scriptio-link" ) . forEach ( ( link ) => {
154184 if ( ! link . getAttribute ( "title" ) ) {
155185 link . setAttribute ( "title" , link . getAttribute ( "data-scriptio-url" ) ) ;
156186 }
157187 link . addEventListener ( "click" , openURL ) ;
158188 } ) ;
159189 setupEasterEggs ( view ) ;
160- const container = $ ( "setting-section.snippets > setting-panel > setting-list" ) ;
190+ const container = $ (
191+ "setting-section.snippets > setting-panel > setting-list" ,
192+ ) ;
161193 return container ;
162194}
163195/** Function to handle `updateScript` event on settings view.
@@ -168,7 +200,9 @@ async function initScriptioSettings(view) {
168200function scriptioSettingsUpdateScript ( container , args ) {
169201 const { path, meta, enabled } = args ;
170202 const isDeleted = meta . name === " [已删除] " ;
171- const item = container . querySelector ( `setting-item[${ configDataAttr } ="${ path } "]` ) || addItem ( path , container ) ;
203+ const item =
204+ container . querySelector ( `setting-item[${ configDataAttr } ="${ path } "]` ) ||
205+ addItem ( path , container ) ;
172206 const itemName = item . querySelector ( "setting-text" ) ;
173207 const optionalVersion = meta . version ? ` (v${ meta . version } )` : "" ;
174208 itemName . textContent = meta . name + optionalVersion ;
@@ -189,7 +223,9 @@ function scriptioSettingsUpdateScript(container, args) {
189223 homepage . removeAttribute ( "data-homepage-url" ) ;
190224 homepage . toggleAttribute ( "disabled" , true ) ;
191225 }
192- const switch_ = item . querySelector ( `setting-switch[${ switchDataAttr } ="${ path } "]` ) ;
226+ const switch_ = item . querySelector (
227+ `setting-switch[${ switchDataAttr } ="${ path } "]` ,
228+ ) ;
193229 switch_ . toggleAttribute ( "is-active" , enabled ) ;
194230 switch_ . parentNode . classList . toggle ( "is-loading" , false ) ;
195231 if ( isDeleted ) {
0 commit comments