Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Progress Tracking #1073

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
495cd20
novel-updates: automatic list update
Batorian Jul 15, 2024
bf3bce2
novel-updates: only mark read when chapter available
Batorian Jul 15, 2024
3edf70d
progress-tracking: initial commit
Batorian Jul 19, 2024
9932c12
progress-tracking: introduce trackProgress
Batorian Jul 19, 2024
54f3427
progress-tracking: fix?
Batorian Jul 19, 2024
507eb4b
progress-tracking: test
Batorian Jul 19, 2024
90965ef
progress-tracking: test
Batorian Jul 19, 2024
3046407
progress-tracking: test
Batorian Jul 19, 2024
3a7e1c6
progress-tracking: scribble hub update
Batorian Jul 19, 2024
9b7aee8
progress-tracking: fix regex
Batorian Jul 19, 2024
0cefbf1
progress-tracking: revert version
Batorian Jul 19, 2024
da79bf0
Merge branch 'LNReader:master' into progress-tracking
Batorian Jul 19, 2024
2c4ae70
Merge branch 'refs/heads/master' into progress-tracking
Batorian Jul 21, 2024
350509e
progress-tracking: remove lint
Batorian Jul 21, 2024
ca6c8e4
Merge branch 'LNReader:master' into progress-tracking
Batorian Jul 22, 2024
d19910c
Merge branch 'LNReader:master' into progress-tracking
Batorian Jul 24, 2024
d52eadc
Merge branch 'LNReader:master' into progress-tracking
Batorian Jul 25, 2024
a3cd14c
Merge branch 'refs/heads/master' into progress-tracking
Batorian Jul 28, 2024
eeaa427
Merge branch 'refs/heads/master' into progress-tracking
Batorian Aug 6, 2024
b33d214
Merge branch 'LNReader:master' into progress-tracking
Batorian Aug 7, 2024
0cba766
Merge branch 'LNReader:master' into progress-tracking
Batorian Aug 12, 2024
5a5d905
Merge branch 'LNReader:master' into progress-tracking
Batorian Aug 14, 2024
50f820c
Merge branch 'LNReader:master' into progress-tracking
Batorian Aug 14, 2024
b7b430d
Merge branch 'LNReader:master' into progress-tracking
Batorian Aug 17, 2024
eac74b7
Merge branch 'LNReader:master' into progress-tracking
Batorian Aug 23, 2024
3e4b3a1
Merge branch 'refs/heads/master' into progress-tracking
Batorian Aug 27, 2024
9f5a7f5
Merge branch 'LNReader:master' into progress-tracking
Batorian Aug 29, 2024
01d6124
Merge branch 'master' into progress-tracking
Batorian Sep 12, 2024
ba0640f
Merge branch 'master' into progress-tracking
Batorian Nov 28, 2024
e230595
Merge branch 'LNReader:master' into progress-tracking
Batorian Nov 29, 2024
bdd5066
Merge branch 'LNReader:master' into progress-tracking
Batorian Dec 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/plugins/english/novelupdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Plugin } from '@typings/plugin';
class NovelUpdates implements Plugin.PluginBase {
id = 'novelupdates';
name = 'Novel Updates';
version = '0.7.11';
version = '0.8.0';
icon = 'src/en/novelupdates/icon.png';
customCSS = 'src/en/novelupdates/customCSS.css';
site = 'https://www.novelupdates.com/';
Expand Down Expand Up @@ -867,6 +867,36 @@ class NovelUpdates implements Plugin.PluginBase {
return chapterText;
}

async trackProgress(novelPath: string, chapterPath: string): Promise<void> {
const url = this.site + novelPath;
const result = await fetchApi(url);
const body = await result.text();

let loadedCheerio = parseHTML(body);

// Extract shortlink and update path if available
const shortlink = loadedCheerio('link[rel="shortlink"]').attr('href');
const updatedNovelPath = shortlink?.replace(this.site, '');

// Extract the novelId from the novelPath
const novelIdMatch = updatedNovelPath?.match(/\?p=(\d+)/);
const novelId = novelIdMatch ? novelIdMatch[1] : null;

// Extract the chapterId from the chapterPath
const chapterIdMatch = chapterPath.match(/\/(\d+)\//);
const chapterId = chapterIdMatch ? chapterIdMatch[1] : null;

if (novelId && chapterId) {
await fetchApi(
`${this.site}readinglist_update.php?rid=${chapterId}&sid=${novelId}&checked=yes`,
);
} else {
throw new Error(
`Invalid novelPath (${novelPath}) or chapterPath (${chapterPath}).`,
);
}
}

async searchNovels(
searchTerm: string,
page: number,
Expand Down
30 changes: 29 additions & 1 deletion src/plugins/english/scribblehub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ScribbleHubPlugin implements Plugin.PluginBase {
name = 'Scribble Hub';
icon = 'src/en/scribblehub/icon.png';
site = 'https://www.scribblehub.com/';
version = '1.0.1';
version = '1.1.0';

parseNovels(loadedCheerio: CheerioAPI) {
const novels: Plugin.NovelItem[] = [];
Expand Down Expand Up @@ -176,6 +176,34 @@ class ScribbleHubPlugin implements Plugin.PluginBase {
return chapterText;
}

async trackProgress(novelPath: string, chapterPath: string): Promise<void> {
// Extract the novelId from the novelPath
const novelIdMatch = novelPath.match(/series\/(\d+)\//);
const novelId = novelIdMatch ? novelIdMatch[1] : null;

// Extract the chapterId from the chapterPath
const chapterIdMatch = chapterPath.match(/chapter\/(\d+)\//);
const chapterId = chapterIdMatch ? chapterIdMatch[1] : null;

const link = `${this.site}wp-admin/admin-ajax.php`;

if (novelId && chapterId) {
const formData = new FormData();
formData.append('action', 'wi_addchangerl');
formData.append('strCID', chapterId);
formData.append('strSID', novelId);

await fetchApi(link, {
method: 'POST',
body: formData,
});
} else {
throw new Error(
`Invalid novelPath (${novelPath}) or chapterPath (${chapterPath}).`,
);
}
}

async searchNovels(searchTerm: string): Promise<Plugin.NovelItem[]> {
const url = `${this.site}?s=${searchTerm}&post_type=fictionposts`;
const result = await fetchApi(url);
Expand Down
1 change: 1 addition & 0 deletions src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export namespace Plugin {
*/
parseNovel(novelPath: string): Promise<SourceNovel>;
parseChapter(chapterPath: string): Promise<string>;
trackProgress?(novelPath: string, chapterPath: string): Promise<void>;
searchNovels(searchTerm: string, pageNo: number): Promise<NovelItem[]>;
resolveUrl?(path: string, isNovel?: boolean): string;
};
Expand Down