11import {
2- Events ,
32 GlobalBlackList ,
43 MsgType ,
54 ScriptType ,
@@ -10,6 +9,7 @@ import {
109 getCurrentTab ,
1110 isFunction ,
1211 removeAccents ,
12+ runScriptInCurrentTab ,
1313 sendEventToTab ,
1414 toggleActiveScript ,
1515} from "../scripts/helpers/utils.js" ;
@@ -22,8 +22,13 @@ import {
2222 favoriteScriptsSaver ,
2323 recentScriptsSaver ,
2424} from "./helpers/storage.js" ;
25- import { viewScriptSource } from "./helpers/utils.js" ;
26- import { canClick , isTitle , refreshSpecialTabs , getAllTabs } from "./tabs.js" ;
25+ import {
26+ canAutoRun ,
27+ canClick ,
28+ isTitle ,
29+ viewScriptSource ,
30+ } from "./helpers/utils.js" ;
31+ import { refreshSpecialTabs , getAllTabs } from "./tabs.js" ;
2732// import _ from "../md/exportScriptsToMd.js";
2833
2934const tabDiv = document . querySelector ( "div.tab" ) ;
@@ -171,9 +176,17 @@ function createScriptButton(script, isFavorite = false) {
171176 const button = document . createElement ( "button" ) ;
172177 button . className = "tooltip" ;
173178 if ( canClick ( script ) ) {
174- button . onclick = ( ) => runScript ( script , button ) ;
179+ button . onclick = ( ) => runScript ( script ) ;
180+ } else if ( canAutoRun ( script ) ) {
181+ button . onclick = ( ) =>
182+ alert (
183+ t ( {
184+ vi : "Chức năng này tự động chạy\nTắt/Mở tự chạy bằng nút bên trái" ,
185+ en : "This function is Autorun\nTurn on/off autorun by click the left checkmark" ,
186+ } )
187+ ) ;
175188 } else {
176- button . onclick = ( ) => alert ( "empty script" ) ;
189+ alert ( t ( { vi : "Chức năng chưa hoàn thành" , en : "Coming soon" } ) ) ;
177190 }
178191
179192 // script badges
@@ -287,13 +300,14 @@ async function updateButtonChecker(script, button, val) {
287300 }
288301}
289302
290- async function runScript ( script , button ) {
303+ async function runScript ( script ) {
291304 let tab = await getCurrentTab ( ) ;
292305 let willRun = checkBlackWhiteList ( script , tab . url ) ;
293306 if ( willRun ) {
294307 recentScriptsSaver . add ( script ) ;
295308 if ( isFunction ( script . onClickExtension ) ) await script . onClickExtension ( ) ;
296- if ( isFunction ( script . onClick ) )
309+ if ( isFunction ( script . onClick ) ) await runScriptInCurrentTab ( script . onClick ) ;
310+ if ( isFunction ( script . onClickContentScript ) )
297311 await sendEventToTab ( tab . id , {
298312 type : MsgType . runScript ,
299313 scriptId : script . id ,
@@ -325,7 +339,7 @@ function initSearch() {
325339 let found = 0 ;
326340 let childrens = document
327341 . querySelector ( ".tabcontent" )
328- . querySelectorAll ( "button " ) ;
342+ . querySelectorAll ( ".buttonContainer " ) ;
329343
330344 childrens . forEach ( ( child ) => {
331345 let willShow = true ;
@@ -341,7 +355,6 @@ function initSearch() {
341355 break ;
342356 }
343357 }
344- // button.style.opacity = willShow ? 1 : 0.1;
345358 child . style . display = willShow ? "block" : "none" ;
346359 if ( willShow ) found ++ ;
347360 } ) ;
0 commit comments