Skip to content
This repository was archived by the owner on Mar 23, 2025. It is now read-only.

Commit 86b9609

Browse files
committed
Enforce DRY
1 parent c291a00 commit 86b9609

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

plugins/mangadex/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const QUERY_PARAMS = 'contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic&';
2+
13
function getCoverURL(mangaId, coverId) {
24
const res = mango.get('https://api.mangadex.org/cover/' + coverId);
35
if (res.status_code !== 200)
@@ -46,7 +48,7 @@ function formatTimestamp(timestamp) {
4648
}
4749

4850
function searchManga(query) {
49-
const res = mango.get('https://api.mangadex.org/manga?title=' + encodeURIComponent(query) + '&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic');
51+
const res = mango.get('https://api.mangadex.org/manga?title=' + encodeURIComponent(query) + '&' + QUERY_PARAMS);
5052
if (res.status_code !== 200)
5153
mango.raise('Failed to search for manga. Status ' + res.status_code);
5254
const manga = JSON.parse(res.body).data;
@@ -75,7 +77,7 @@ function listChapters(id) {
7577
const titleAttr = manga.attributes.title;
7678
const title = titleAttr.en || titleAttr['ja-ro'] || titleAttr[Object.keys(titleAttr)[0]];
7779

78-
var url = 'https://api.mangadex.org/manga/' + id + '/feed?';
80+
var url = 'https://api.mangadex.org/manga/' + id + '/feed?' + QUERY_PARAMS;
7981

8082
const langStr = mango.settings('language');
8183
if (langStr) {
@@ -89,8 +91,6 @@ function listChapters(id) {
8991
url += 'limit=' + limit.trim() + '&';
9092
}
9193

92-
url += 'contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic&';
93-
9494
const res = mango.get(url);
9595
if (res.status_code !== 200)
9696
mango.raise('Failed to list chapters. Status ' + res.status_code);
@@ -103,7 +103,7 @@ function listChapters(id) {
103103
}
104104

105105
function newChapters(mangaId, after) {
106-
var url = 'https://api.mangadex.org/manga/' + mangaId + '/feed?publishAtSince=' + formatTimestamp(after) + '&';
106+
var url = 'https://api.mangadex.org/manga/' + mangaId + '/feed?publishAtSince=' + formatTimestamp(after) + '&' + QUERY_PARAMS;
107107

108108
const langStr = mango.settings('language');
109109
if (langStr) {
@@ -117,8 +117,6 @@ function newChapters(mangaId, after) {
117117
url += 'limit=' + limit.trim() + '&';
118118
}
119119

120-
url += 'contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic&';
121-
122120
const res = mango.get(url);
123121
if (res.status_code !== 200)
124122
mango.raise('Failed to list new chapters. Status ' + res.status_code);

0 commit comments

Comments
 (0)