Skip to content

Commit 5a994df

Browse files
committed
+ Implement addReadHistory.
1 parent f12e3a5 commit 5a994df

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

package-lock.json

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,35 @@ async function getImageUrl (path: string) {
363363
window.Rulia.endWithException((error as Error).message)
364364
}
365365
}
366+
367+
/**
368+
* Add reading history .
369+
*
370+
* @param {string} url The manga episode url.
371+
*/
372+
async function addReadHistory (url: string) {
373+
// url: https://manga.bilibili.com/mc10000/12450
374+
const seasonId = url.match(/mc(\d+)/)?.[1]
375+
const episodeId = url.match(/\/(\d+)$/)?.[1]
376+
377+
if (!seasonId || !episodeId) {
378+
window.Rulia.endWithException('INVALID_URL')
379+
return
380+
}
381+
382+
try {
383+
await window.Rulia.httpRequest({
384+
url: 'https://manga.bilibili.com/twirp/bookshelf.v1.Bookshelf/AddHistory?device=pc&platform=web',
385+
method: 'POST',
386+
payload: JSON.stringify({
387+
comic_id: parseInt(seasonId),
388+
ep_id: parseInt(episodeId)
389+
}),
390+
contentType: 'application/json'
391+
})
392+
393+
window.Rulia.endWithResult('{}')
394+
} catch (error) {
395+
window.Rulia.endWithException((error as Error).message)
396+
}
397+
}

0 commit comments

Comments
 (0)