1- import { websites } from './websites'
1+ import { websites , hooks } from './websites'
22import {
33 isExtension ,
4- sendMessage
4+ sendMessage ,
5+ getLocal ,
6+ setWebsite
57} from './utils'
68import downloadZip from './download'
79import { downloadMarkdown } from './markdown'
810import { getLocalOptions } from './options'
911
10- const extract = async ( options , customOptions , hook ) => {
12+ const extract = async ( options , customOptions = { } , hook = { } ) => {
1113 const localOptions = await getLocalOptions ( )
1214 const data = await downloadMarkdown ( options , Object . assign ( customOptions , {
1315 localOptions
@@ -25,15 +27,29 @@ const extract = async (options, customOptions, hook) => {
2527
2628if ( isExtension ) {
2729 chrome . runtime . onMessage . addListener ( async ( message , sender , sendResponse ) => {
30+ const localWebsites = await getLocal ( 'websites' )
2831 if ( message instanceof Object ) {
2932 if ( message . type === 'download' ) {
3033 if ( typeof websites [ message . website ] === 'function' ) {
3134 await websites [ message . website ] ( extract )
35+ } else {
36+ const localWebsite = localWebsites [ message . website ]
37+ if ( localWebsite instanceof Object ) {
38+ await extract (
39+ localWebsite ,
40+ localWebsite . customOptions instanceof Object ? localWebsite . customOptions : { } ,
41+ Object . assign ( { } ,
42+ hooks [ message . website ] instanceof Object ? hooks [ message . website ] : { } ,
43+ localWebsite . hooks instanceof Object ? localWebsite . hooks : { }
44+ )
45+ )
46+ }
3247 }
3348 }
3449 }
3550 sendResponse ( '' )
3651 } )
52+ window . setWebsite = setWebsite
3753}
3854
3955export default downloadMarkdown
0 commit comments