@@ -12,8 +12,10 @@ type LightNovelWPOptions = {
1212 lang ?: string ;
1313 versionIncrements ?: number ;
1414 seriesPath ?: string ;
15- customJs ?: string ;
15+ customTransformJs ?: string ;
1616 hasLocked ?: boolean ;
17+ customRuntimeJs ?: string ;
18+ customCss ?: string ;
1719} ;
1820
1921export type LightNovelWPMetadata = {
@@ -32,7 +34,10 @@ class LightNovelWPPlugin implements Plugin.PluginBase {
3234 version : string ;
3335 options ?: LightNovelWPOptions ;
3436 filters ?: Filters ;
37+ customJS ?: string ;
38+ customCSS ?: string ;
3539
40+ // TODO: this probably needs to be done at use time, otherwise changes won't be reflected
3641 hideLocked = storage . get ( 'hideLocked' ) ;
3742 pluginSettings ?: Record < string , any > ;
3843
@@ -42,9 +47,11 @@ class LightNovelWPPlugin implements Plugin.PluginBase {
4247 this . icon = `multisrc/lightnovelwp/${ metadata . id . toLowerCase ( ) } /icon.png` ;
4348 this . site = metadata . sourceSite ;
4449 const versionIncrements = metadata . options ?. versionIncrements || 0 ;
45- this . version = `1.1.${ 9 + versionIncrements } ` ;
50+ this . version = `1.1.${ 10 + versionIncrements } ` ;
4651 this . options = metadata . options ?? ( { } as LightNovelWPOptions ) ;
4752 this . filters = metadata . filters satisfies Filters ;
53+ this . customJS = this . options . customRuntimeJs ;
54+ this . customCSS = this . options . customCss ;
4855
4956 if ( this . options ?. hasLocked ) {
5057 this . pluginSettings = {
@@ -64,7 +71,7 @@ class LightNovelWPPlugin implements Plugin.PluginBase {
6471 return url_parts . join ( '.' ) ;
6572 }
6673
67- async safeFecth ( url : string , search : boolean ) : Promise < string > {
74+ async safeFetch ( url : string , search : boolean ) : Promise < string > {
6875 const urlParts = url . split ( '://' ) ;
6976 const protocol = urlParts . shift ( ) ;
7077 const sanitizedUri = urlParts [ 0 ] . replace ( / \/ \/ / g, '/' ) ;
@@ -147,13 +154,13 @@ class LightNovelWPPlugin implements Plugin.PluginBase {
147154 url += `&${ key } =${ value } ` ;
148155 else if ( filters [ key ] . value ) url += `&${ key } =${ filters [ key ] . value } ` ;
149156 }
150- const html = await this . safeFecth ( url , false ) ;
157+ const html = await this . safeFetch ( url , false ) ;
151158 return this . parseNovels ( html ) ;
152159 }
153160
154161 async parseNovel ( novelPath : string ) : Promise < Plugin . SourceNovel > {
155162 const baseURL = this . site ;
156- const html = await this . safeFecth ( baseURL + novelPath , false ) ;
163+ const html = await this . safeFetch ( baseURL + novelPath , false ) ;
157164
158165 const novel : Plugin . SourceNovel = {
159166 path : novelPath ,
@@ -180,7 +187,10 @@ class LightNovelWPPlugin implements Plugin.PluginBase {
180187 let hasLockItemOnChapterNum = false ;
181188 const chapters : Plugin . ChapterItem [ ] = [ ] ;
182189 let tempChapter = { } as Plugin . ChapterItem ;
183- const hideLocked = this . hideLocked ;
190+
191+ const hideLocked = ! ! (
192+ storage . get ( 'hideLocked' ) ?? this . pluginSettings ?. [ 'hideLocked' ] . value
193+ ) ;
184194
185195 const parser = new Parser ( {
186196 onopentag ( name , attribs ) {
@@ -421,29 +431,28 @@ class LightNovelWPPlugin implements Plugin.PluginBase {
421431 novel . chapters = chapters ;
422432 }
423433
424- novel . summary = novel . summary . trim ( ) ;
434+ novel . summary = novel . summary ? .trim ( ) ;
425435
426436 return novel ;
427437 }
428438
429439 async parseChapter ( chapterPath : string ) : Promise < string > {
430- let data = await this . safeFecth ( this . site + chapterPath , false ) ;
431- if ( this . options ?. customJs ) {
440+ let data = await this . safeFetch ( this . site + chapterPath , false ) ;
441+ const $ = load ( data ) ;
442+ if ( this . options ?. customTransformJs ) {
432443 try {
433- const $ = load ( data ) ;
434444 // CustomJS HERE
435- data = $ . html ( ) ;
436445 } catch ( error ) {
437446 console . error ( 'Error executing customJs:' , error ) ;
438447 throw error ;
439448 }
440449 }
441- return (
442- data
443- . match ( / < d i v . * ? c l a s s = " e p c o n t e n t ( [ ^ ] * ? ) < d i v . * ? c l a s s = " ? b o t t o m n a v / g ) ?. [ 0 ]
444- . match ( / < p [ ^ > ] * > ( [ ^ ] * ? ) < \/ p > / g )
445- ?. join ( '\n' ) || ''
446- ) ;
450+ const content = $ ( 'div.epcontent' ) ;
451+ // content.find('h1:first-child').remove();
452+
453+ // content.find('> :not(p)').remove();
454+
455+ return content . html ( ) ?? '' ;
447456 }
448457
449458 async searchNovels (
@@ -452,7 +461,7 @@ class LightNovelWPPlugin implements Plugin.PluginBase {
452461 ) : Promise < Plugin . NovelItem [ ] > {
453462 const url =
454463 this . site + 'page/' + page + '/?s=' + encodeURIComponent ( searchTerm ) ;
455- const html = await this . safeFecth ( url , true ) ;
464+ const html = await this . safeFetch ( url , true ) ;
456465 return this . parseNovels ( html ) ;
457466 }
458467}
0 commit comments