perf: LightnovelWP - Faster and Safer Regex (#1476)
* LightnovelWP - faster and safer regex * version increment + a forgot regex
This commit is contained in:
@@ -42,7 +42,7 @@ class LightNovelWPPlugin implements Plugin.PluginBase {
|
|||||||
this.icon = `multisrc/lightnovelwp/${metadata.id.toLowerCase()}/icon.png`;
|
this.icon = `multisrc/lightnovelwp/${metadata.id.toLowerCase()}/icon.png`;
|
||||||
this.site = metadata.sourceSite;
|
this.site = metadata.sourceSite;
|
||||||
const versionIncrements = metadata.options?.versionIncrements || 0;
|
const versionIncrements = metadata.options?.versionIncrements || 0;
|
||||||
this.version = `1.1.${5 + versionIncrements}`;
|
this.version = `1.1.${6 + versionIncrements}`;
|
||||||
this.options = metadata.options ?? ({} as LightNovelWPOptions);
|
this.options = metadata.options ?? ({} as LightNovelWPOptions);
|
||||||
this.filters = metadata.filters satisfies Filters;
|
this.filters = metadata.filters satisfies Filters;
|
||||||
|
|
||||||
@@ -96,14 +96,14 @@ class LightNovelWPPlugin implements Plugin.PluginBase {
|
|||||||
html = load(html).html(); // fix "'" beeing replaced by "’" (html entities)
|
html = load(html).html(); // fix "'" beeing replaced by "’" (html entities)
|
||||||
const novels: Plugin.NovelItem[] = [];
|
const novels: Plugin.NovelItem[] = [];
|
||||||
|
|
||||||
const articles = html.match(/<article([\s\S]*?)<\/article>/g) || [];
|
const articles = html.match(/<article([^]*?)<\/article>/g) || [];
|
||||||
articles.forEach(article => {
|
articles.forEach(article => {
|
||||||
const [, novelUrl, novelName] =
|
const [, novelUrl, novelName] =
|
||||||
article.match(/<a href="(.*?)".*title="(.*?)"/) || [];
|
article.match(/<a href="([^\"]*)".*? title="([^\"]*)"/) || [];
|
||||||
|
|
||||||
if (novelName && novelUrl) {
|
if (novelName && novelUrl) {
|
||||||
const novelCover =
|
const novelCover =
|
||||||
article.match(/<img.*src="(.*?)"(?:\sdata-src="(.*?)")?.*\/?>/) || [];
|
article.match(/<img [^>]*?src="([^\"]*)"[^>]*?(?: data-src="([^\"]*)")?[^>]*>/) || [];
|
||||||
|
|
||||||
let novelPath;
|
let novelPath;
|
||||||
if (novelUrl.includes(this.site)) {
|
if (novelUrl.includes(this.site)) {
|
||||||
@@ -434,8 +434,8 @@ class LightNovelWPPlugin implements Plugin.PluginBase {
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
data
|
data
|
||||||
.match(/<div.*class="epcontent ([\s\S]*?)<div.*class="?bottomnav/g)?.[0]
|
.match(/<div.*?class="epcontent ([^]*?)<div.*?class="?bottomnav/g)?.[0]
|
||||||
.match(/<p.*>([\s\S]*?)<\/p>/g)
|
.match(/<p[^>]*>([^]*?)<\/p>/g)
|
||||||
?.join('\n') || ''
|
?.join('\n') || ''
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user