|
1 | 1 | window.state = window.state || {}; |
2 | 2 | state = window.state; |
| 3 | +let selectingQueue = 0; // 默认都延时一下再开始触发 |
3 | 4 |
|
4 | 5 | state.utils = { |
5 | 6 |
|
@@ -325,79 +326,87 @@ state.utils = { |
325 | 326 | try { |
326 | 327 | let value = store.get(id); |
327 | 328 | if (value ) { //&& value != 'None' |
328 | | - let input = select.querySelector('input'); |
329 | | - state.utils.triggerMouseEvent(input, 'focus'); |
330 | | - |
| 329 | + |
| 330 | + selectingQueue += 1; |
331 | 331 | setTimeout(() => { |
332 | | - let items = Array.from(select.querySelectorAll('ul li')); |
333 | | - let localized_value = this.getTranslation(value) |
334 | | - let successed = false |
335 | | - for (li of items){ |
336 | | - // li.lastChild.wholeText.trim() === value |
337 | | - if (localized_value.replace(/^\s+|\s+$/g,"") === li.lastChild.wholeText.trim().replace(/^\s+|\s+$/g,"")) { |
338 | | - state.utils.triggerMouseEvent(li, 'mousedown'); |
339 | | - successed = true |
340 | | - break |
341 | | - } |
342 | | - } |
343 | 332 |
|
344 | | - let hash_pos = localized_value.search(/\[[0-9A-Fa-f]{10}\]/) |
345 | | - if(!successed){ // && hash_pos != -1 找不到对应选项 并且选项里有10位哈希值 |
| 333 | + let input = select.querySelector('input'); |
| 334 | + state.utils.triggerMouseEvent(input, 'focus'); |
| 335 | + |
| 336 | + setTimeout(() => { |
| 337 | + let items = Array.from(select.querySelectorAll('ul li')); |
| 338 | + let localized_value = this.getTranslation(value) |
| 339 | + let successed = false |
346 | 340 | for (li of items){ |
347 | | - |
348 | | - // 去掉Hash比较 |
349 | | - let text = li.lastChild.wholeText.trim() |
350 | | - let localized_value_no_hash = localized_value.replace(/\[[0-9A-Fa-f]{10}\]/,"").replace(/^\s+|\s+$/g,"") |
351 | | - let text_no_hash = text.replace(/\[[0-9A-Fa-f]{10}\]/, "").replace(/^\s+|\s+$/g,"") |
352 | | - |
353 | | - if (localized_value_no_hash === text_no_hash) { |
| 341 | + // li.lastChild.wholeText.trim() === value |
| 342 | + if (localized_value.replace(/^\s+|\s+$/g,"") === li.lastChild.wholeText.trim().replace(/^\s+|\s+$/g,"")) { |
| 343 | + state.utils.triggerMouseEvent(li, 'mousedown'); |
354 | 344 | successed = true |
| 345 | + break |
355 | 346 | } |
356 | | - |
357 | | - // 只比较Hash |
358 | | - if(!successed){ |
359 | | - let hash_str = localized_value.substring(hash_pos,hash_pos+12).replace(/^\s+|\s+$/g,"") |
360 | | - let text_hash_pos = text.search(/\[[0-9A-Fa-f]{10}\]/) |
361 | | - let text_hash = text.substring(text_hash_pos, text_hash_pos+12).replace(/^\s+|\s+$/g,"") |
362 | | - if (hash_str === text_hash) { |
| 347 | + } |
| 348 | + |
| 349 | + let hash_pos = localized_value.search(/\[[0-9A-Fa-f]{10}\]/) |
| 350 | + if(!successed){ // && hash_pos != -1 找不到对应选项 并且选项里有10位哈希值 |
| 351 | + for (li of items){ |
| 352 | + |
| 353 | + // 去掉Hash比较 |
| 354 | + let text = li.lastChild.wholeText.trim() |
| 355 | + let localized_value_no_hash = localized_value.replace(/\[[0-9A-Fa-f]{10}\]/,"").replace(/^\s+|\s+$/g,"") |
| 356 | + let text_no_hash = text.replace(/\[[0-9A-Fa-f]{10}\]/, "").replace(/^\s+|\s+$/g,"") |
| 357 | + |
| 358 | + if (localized_value_no_hash === text_no_hash) { |
363 | 359 | successed = true |
364 | 360 | } |
365 | | - } |
| 361 | + |
| 362 | + // 只比较Hash |
| 363 | + if(!successed){ |
| 364 | + let hash_str = localized_value.substring(hash_pos,hash_pos+12).replace(/^\s+|\s+$/g,"") |
| 365 | + let text_hash_pos = text.search(/\[[0-9A-Fa-f]{10}\]/) |
| 366 | + let text_hash = text.substring(text_hash_pos, text_hash_pos+12).replace(/^\s+|\s+$/g,"") |
| 367 | + if (hash_str === text_hash) { |
| 368 | + successed = true |
| 369 | + } |
| 370 | + } |
366 | 371 |
|
367 | | - if(successed){ |
368 | | - state.utils.triggerMouseEvent(li, 'mousedown'); |
369 | | - state.core.actions.output_warning( |
370 | | - `The option '${value}' was not found, and has been replaced with '${li.lastChild.wholeText.trim()}'!`) |
371 | | - break |
| 372 | + if(successed){ |
| 373 | + state.utils.triggerMouseEvent(li, 'mousedown'); |
| 374 | + state.core.actions.output_warning( |
| 375 | + `The option '${value}' was not found, and has been replaced with '${li.lastChild.wholeText.trim()}'!`) |
| 376 | + break |
| 377 | + } |
372 | 378 | } |
373 | 379 | } |
374 | | - } |
375 | 380 |
|
376 | | - if(!successed && items.length > 0) // 下拉框一个选项都没找到说明就没有这个下拉框,可能是界面设置把下拉框替换成了radio button |
377 | | - { |
378 | | - let option_name = store.prefix + id |
379 | | - if(option_name === "state-setting_sd_model_checkpoint"){ |
380 | | - // 大模型找不到就只用warning提示,因为不影响运行 |
381 | | - state.core.actions.output_warning(`The option \'${value}\' was not found!`) |
382 | | - } |
383 | | - else{ |
384 | | - state.core.actions.output_error(`\'${option_name}\' import failed! The option \'${value}\' was not found!`) |
385 | | - } |
386 | | - if(hash_pos != -1){ |
387 | | - let model_name = value |
388 | | - let hash_str = localized_value.substring(hash_pos,hash_pos+12) |
389 | | - state.utils.searchCheckPointByHash(hash_str).then( downloadUrl => { |
390 | | - if(downloadUrl != undefined){ |
391 | | - let warning_str = encodeURIComponent(`click to download \ |
392 | | - <a style ='text-decoration:underline;color:cornflowerblue;', href='${downloadUrl}'> ${model_name} </a>`) |
393 | | - state.core.actions.output_warning(warning_str) |
394 | | - } |
395 | | - }); |
| 381 | + if(!successed && items.length > 0) // 下拉框一个选项都没找到说明就没有这个下拉框,可能是界面设置把下拉框替换成了radio button |
| 382 | + { |
| 383 | + let option_name = store.prefix + id |
| 384 | + if(option_name === "state-setting_sd_model_checkpoint"){ |
| 385 | + // 大模型找不到就只用warning提示,因为不影响运行 |
| 386 | + state.core.actions.output_warning(`The option \'${value}\' was not found!`) |
| 387 | + } |
| 388 | + else{ |
| 389 | + state.core.actions.output_error(`\'${option_name}\' import failed! The option \'${value}\' was not found!`) |
| 390 | + } |
| 391 | + if(hash_pos != -1){ |
| 392 | + let model_name = value |
| 393 | + let hash_str = localized_value.substring(hash_pos,hash_pos+12) |
| 394 | + state.utils.searchCheckPointByHash(hash_str).then( downloadUrl => { |
| 395 | + if(downloadUrl != undefined){ |
| 396 | + let warning_str = encodeURIComponent(`click to download \ |
| 397 | + <a style ='text-decoration:underline;color:cornflowerblue;', href='${downloadUrl}'> ${model_name} </a>`) |
| 398 | + state.core.actions.output_warning(warning_str) |
| 399 | + } |
| 400 | + }); |
| 401 | + } |
396 | 402 | } |
397 | | - } |
398 | 403 |
|
399 | | - state.utils.triggerMouseEvent(input, 'blur'); |
400 | | - }, 100); |
| 404 | + state.utils.triggerMouseEvent(input, 'blur'); |
| 405 | + selectingQueue -= 1; |
| 406 | + console.log(`selectingQueue = ${selectingQueue}`) |
| 407 | + }, 100); |
| 408 | + |
| 409 | + }, selectingQueue * 200) |
401 | 410 | } |
402 | 411 |
|
403 | 412 | setTimeout(() => { |
|
0 commit comments