@@ -411,7 +411,7 @@ async function updateButtonChecker(script, checkmarkContainer, val) {
411411 if ( val ?? ( await isActiveScript ( script . id ) ) ) {
412412 checkmark . classList . add ( "active" ) ;
413413 tooltip = t ( {
414- vi : "Tắt tự động chạy" ,
414+ vi : "Tắt tự chạy" ,
415415 en : "Turn off Autorun" ,
416416 } ) ;
417417 } else {
@@ -424,38 +424,48 @@ async function updateButtonChecker(script, checkmarkContainer, val) {
424424 checkmarkContainer . setAttribute ( "data-tooltip" , tooltip ) ;
425425}
426426
427+ function showError ( e ) {
428+ Swal . fire ( {
429+ icon : "error" ,
430+ title : t ( { vi : "Lỗi" , en : "Error" } ) ,
431+ text : e ?. message || "" ,
432+ input : "textarea" ,
433+ inputValue : JSON . stringify ( e , null , 4 ) ,
434+ } ) ;
435+ }
436+
427437async function runScript ( script ) {
428438 let tab = await getCurrentTab ( ) ;
429439 let willRun = checkBlackWhiteList ( script , tab . url ) ;
430440 if ( willRun ) {
431- try {
432- recentScriptsSaver . add ( script ) ;
433- trackEvent ( script . id ) ;
441+ recentScriptsSaver . add ( script ) ;
442+ trackEvent ( script . id ) ;
434443
444+ try {
435445 if ( isFunction ( script . popupScript ?. onClick ) )
436446 await script . popupScript . onClick ( ) ;
437-
438- [
439- [ "MAIN" , "pageScript" , "onClick" , false ] ,
440- [ "MAIN" , "pageScript" , "onClick_" , true ] ,
441- [ "ISOLATED" , "contentScript" , "onClick" , false ] ,
442- [ "ISOLATED" , "contentScript" , "onClick_" , true ] ,
443- ] . forEach ( ( [ world , context , func , allFrames ] ) => {
444- if ( isFunction ( script ?. [ context ] ?. [ func ] ) ) {
445- runScriptInTabWithEventChain ( {
446- target : {
447- tabId : tab . id ,
448- ...( allFrames ? { allFrames : true } : { } ) ,
449- } ,
450- scriptIds : [ script . id ] ,
451- eventChain : context + "." + func ,
452- world : world ,
453- } ) ;
454- }
455- } ) ;
456447 } catch ( e ) {
457- alert ( "ERROR: run script " + e ) ;
448+ showError ( e ) ;
458449 }
450+
451+ [
452+ [ "MAIN" , "pageScript" , "onClick" , false ] ,
453+ [ "MAIN" , "pageScript" , "onClick_" , true ] ,
454+ [ "ISOLATED" , "contentScript" , "onClick" , false ] ,
455+ [ "ISOLATED" , "contentScript" , "onClick_" , true ] ,
456+ ] . forEach ( ( [ world , context , func , allFrames ] ) => {
457+ if ( isFunction ( script ?. [ context ] ?. [ func ] ) ) {
458+ runScriptInTabWithEventChain ( {
459+ target : {
460+ tabId : tab . id ,
461+ ...( allFrames ? { allFrames : true } : { } ) ,
462+ } ,
463+ scriptIds : [ script . id ] ,
464+ eventChain : context + "." + func ,
465+ world : world ,
466+ } ) . catch ( showError ) ;
467+ }
468+ } ) ;
459469 } else {
460470 let w = script ?. whiteList ?. join ( "<br/>" ) ;
461471 let b = script ?. blackList ?. join ( "<br/>" ) ;
@@ -596,10 +606,18 @@ function initSettings() {
596606 // smooth scroll row
597607 const smoothScrollRow = document . createElement ( "div" ) ;
598608 smoothScrollRow . classList . add ( "row" ) ;
609+ smoothScrollRow . setAttribute (
610+ "data-tooltip" ,
611+ t ( {
612+ vi : "Tắt nếu bạn đã cài app SmoothScroll" ,
613+ en : "Turn off if installed SmoothScroll app" ,
614+ } )
615+ ) ;
616+ smoothScrollRow . setAttribute ( "data-flow" , "bottom" ) ;
599617 smoothScrollRow . innerHTML = `
600618 <div class="label">${ t ( {
601- vi : "Cuộn chuột mượt" ,
602- en : "Smooth scroll" ,
619+ vi : "Cuôn chuột siêu mượt" ,
620+ en : "Super smooth scroll" ,
603621 } ) } </div>
604622 <div class="right-container">
605623 <button class="checkmark"></button>
0 commit comments