File tree 6 files changed +48
-13
lines changed
6 files changed +48
-13
lines changed Original file line number Diff line number Diff line change 1
1
node_modules
2
- dist /bundle.js
2
+ dist /* . bundle.js
Original file line number Diff line number Diff line change 2
2
"manifest_version" : 2 ,
3
3
"name" : " My Cool Extension" ,
4
4
"version" : " 0.1" ,
5
+ "background" : {
6
+ "scripts" : [" background.bundle.js" ]
7
+ },
5
8
"content_scripts" : [
6
9
{
7
10
"matches" : [" <all_urls>" ],
8
11
"js" : [
9
12
" jquery-3.4.1.slim.min.js" ,
10
- " bundle.js"
13
+ " content. bundle.js"
11
14
]
12
15
}
16
+ ],
17
+ "permissions" : [
18
+ " tabs"
13
19
]
14
20
}
Original file line number Diff line number Diff line change 1
1
import json from '@rollup/plugin-json' ;
2
2
3
- export default {
3
+ export default [ {
4
4
input : 'src/index.js' ,
5
5
output : {
6
- file : 'dist/bundle.js'
6
+ file : 'dist/content. bundle.js'
7
7
} ,
8
8
plugins : [ json ( ) ]
9
- } ;
9
+ } , {
10
+ input : 'src/background.js' ,
11
+ output : {
12
+ file : 'dist/background.bundle.js'
13
+ }
14
+ } ] ;
Original file line number Diff line number Diff line change
1
+ import messages from './messages.js' ;
2
+
3
+ chrome . tabs . onUpdated . addListener ( ( tabId , changeInfo , tab ) => {
4
+ if ( changeInfo . url ) {
5
+ chrome . tabs . sendMessage ( tabId , {
6
+ message : messages . URL_CHANGE ,
7
+ url : changeInfo . url
8
+ } ) ;
9
+ }
10
+ } ) ;
Original file line number Diff line number Diff line change 1
1
import plugins from './plugins/index.js' ;
2
2
import { version } from '../package.json' ;
3
+ import messages from './messages.js' ;
3
4
4
- const url = document . URL ;
5
-
6
- for ( let plugin of plugins ) {
7
- if ( plugin . runFor ( url ) ) {
8
- console . group ( `Josh's extension v${ version } ` ) ;
9
- console . log ( `Running '${ plugin . name } '...` )
10
- plugin . run ( ) ;
11
- console . groupEnd ( `Josh's extension` ) ;
5
+ const runPlugins = ( ) => {
6
+ const url = document . URL ;
7
+ for ( let plugin of plugins ) {
8
+ if ( plugin . runFor ( url ) ) {
9
+ console . group ( `Josh's extension v${ version } ` ) ;
10
+ console . log ( `Running '${ plugin . name } '...` )
11
+ plugin . run ( ) ;
12
+ console . groupEnd ( `Josh's extension v${ version } ` ) ;
13
+ }
12
14
}
13
15
}
16
+ runPlugins ( ) ;
17
+
18
+ chrome . runtime . onMessage . addListener (
19
+ function ( request , sender , sendResponse ) {
20
+ // listen for messages sent from background.js
21
+ if ( request . message === messages . URL_CHANGE ) {
22
+ runPlugins ( ) ;
23
+ }
24
+ } ) ;
Original file line number Diff line number Diff line change
1
+ export default {
2
+ URL_CHANGE : 'url-change'
3
+ } ;
You can’t perform that action at this time.
0 commit comments