diff --git a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryMultiPageViewerPTokenParser.kt b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryMultiPageViewerPTokenParser.kt
index d94d63402..a0ea3b50b 100644
--- a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryMultiPageViewerPTokenParser.kt
+++ b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryMultiPageViewerPTokenParser.kt
@@ -15,31 +15,24 @@
* You should have received a copy of the GNU General Public License along with EhViewer.
* If not, see .
*/
+package com.hippo.ehviewer.client.parser
-package com.hippo.ehviewer.client.parser;
+import com.hippo.ehviewer.client.exception.EhException
+import com.hippo.util.ExceptionUtils
+import org.json.JSONArray
-import com.hippo.ehviewer.client.exception.EhException;
-import com.hippo.util.ExceptionUtils;
-
-import org.json.JSONArray;
-import org.json.JSONObject;
-
-import java.util.ArrayList;
-
-public class GalleryMultiPageViewerPTokenParser {
- public static ArrayList parse(String body) throws Exception {
- ArrayList list = new ArrayList<>();
- String imagelist = body.substring(body.indexOf("var imagelist = ") + 16, body.indexOf(";", body.indexOf("var imagelist = ")));
- try {
- JSONArray ja = new JSONArray(imagelist);
- for (int i = 0; i < ja.length(); i++) {
- JSONObject jo = ja.getJSONObject(i);
- list.add(jo.getString("k"));
- }
- } catch (Throwable e) {
- ExceptionUtils.throwIfFatal(e);
- throw new EhException(body);
+object GalleryMultiPageViewerPTokenParser {
+ fun parse(body: String): List {
+ val imagelist = body.substring(
+ body.indexOf("var imagelist = ") + 16,
+ body.indexOf(";", body.indexOf("var imagelist = ")),
+ )
+ return runCatching {
+ val ja = JSONArray(imagelist)
+ (0 until ja.length()).map { ja.getJSONObject(it).getString("k") }
+ }.getOrElse {
+ ExceptionUtils.throwIfFatal(it)
+ throw EhException(body)
}
- return list;
}
}