1- function setOption ( option ) {
2- return ( event ) => {
3- settings [ option ] = event . target . checked
4- updateStorage ( )
5- }
6- }
7-
8- function updateStorage ( ) {
9- console . log ( 'update storage:' , settings )
10- browser . storage . sync . set ( { skipButtonSettings : settings } )
11- }
1+ const autoSkipCheck = document . getElementById ( 'autoSkip' )
2+ const hideSponsoredCheck = document . getElementById ( 'hideSponsored' )
3+ const manualSkipBtn = document . getElementById ( 'manualSkip' )
124
13- function sendManualSkip ( ) {
14- browser . tabs . query ( {
15- active : true ,
16- currentWindow : true
17- } ) . then ( tabs => tabs . forEach ( tab => {
18- browser . tabs . executeScript ( tab . id , { code : 'manualSkip()' } )
19- } ) )
20- }
5+ autoSkipCheck . addEventListener ( 'input' , setOption ( 'autoSkip' ) )
6+ hideSponsoredCheck . addEventListener ( 'input' , setOption ( 'hideSponsored' ) )
7+ manualSkipBtn . addEventListener ( 'click' , sendManualSkip )
218
229// Default settings
2310let settings = {
2411 autoSkip : false ,
2512 hideSponsored : true
2613}
2714
28- const autoSkipCheck = document . getElementById ( 'autoSkip' )
29- const hideSponsoredCheck = document . getElementById ( 'hideSponsored' )
30- const manualSkipBtn = document . getElementById ( 'manualSkip' )
31-
15+ // Load current settings and set popup values
3216browser . storage . sync . get ( 'skipButtonSettings' ) . then ( ( { skipButtonSettings } ) => {
3317 if ( skipButtonSettings ) {
34- console . log ( 'settings loaded:' , skipButtonSettings )
3518 settings = skipButtonSettings
3619 } else {
3720 updateStorage ( )
@@ -40,6 +23,25 @@ browser.storage.sync.get('skipButtonSettings').then(({ skipButtonSettings }) =>
4023 hideSponsoredCheck . checked = settings . hideSponsored
4124} )
4225
43- autoSkipCheck . addEventListener ( 'input' , setOption ( 'autoSkip' ) )
44- hideSponsoredCheck . addEventListener ( 'input' , setOption ( 'hideSponsored' ) )
45- manualSkipBtn . addEventListener ( 'click' , sendManualSkip )
26+ function setOption ( option ) {
27+ return ( event ) => {
28+ settings [ option ] = event . target . checked
29+ updateStorage ( )
30+ }
31+ }
32+
33+ function updateStorage ( ) {
34+ browser . storage . sync . set ( { skipButtonSettings : settings } )
35+ }
36+
37+ function sendManualSkip ( ) {
38+ browser . tabs . query ( {
39+ active : true ,
40+ currentWindow : true
41+ } ) . then ( tabs => tabs . forEach ( tab => {
42+ browser . scripting . executeScript ( {
43+ target : { allFrames : true , tabId : tab . id } ,
44+ func : ( ) => typeof manualSkip !== 'undefined' && manualSkip ( )
45+ } )
46+ } ) )
47+ }
0 commit comments